0% found this document useful (0 votes)
3 views3 pages

Python Basics

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

Writing your first Python Program

Here we provided the latest Python 3 version compiler where you can edit
and compile your written code directly with just one click of the RUN
Button. So test yourself with Python’s first exercises.
print("Hello World! Welcome to Python Basics")
Comments in Python
Comments in Python are the lines in the code that are ignored by the
interpreter during the execution of the program. Also, Comments enhance
the readability of the code and help the programmers to understand the
code very carefully.
# USE # for adding comments

# This is Python Comment


Python Variable
Python Variable is containers that store values. Python is not “statically
typed”. An Example of a Variable in Python is a representational name
that serves as a pointer to an object. Once an object is assigned to a
variable, it can be referred to by that name.
Rules for Python variables
 A Python variable name must start with a letter or the underscore
character.
 A Python variable name cannot start with a number.
 A Python variable name can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _ ).
 Variable in Python names are case-sensitive (name, Name, and NAME
are three different variables).
 The reserved words(keywords) in Python cannot be used to name the
variable in Python.
Example
# An integer assignment
age = 45

# A floating point
salary = 1456.8

# A string
name = "John"

print(age)
print(salary)
print(name)

Output
45
1456.8
John

Python Data Types


Data types are the classification or categorization of data items. It
represents the kind of value that tells what operations can be performed
on a particular data. Since everything is an object in Python programming,
data types are classes and variables are instances (objects) of these
classes.

Example: This code assigns variable ‘x’ different values of various data
types in Python.
x = "Hello World" # string
x = 50 # integer
x = 60.5 # float
x = 3j # complex
x = ["geeks", "for", "geeks"] # list
x = ("geeks", "for", "geeks") # tuple
x = {"name": "Suraj", "age": 24} # dict
x = {"geeks", "for", "geeks"} # set
x = True # bool
x = b"Geeks" # binary
Python Input/Output
This function first takes the input from the user and converts it into a
string. The type of the returned object always will be <class ‘str’>. It does
not evaluate the expression it just returns the complete statement as
String, and will print it.
# Python program show input and Output
val = input("Enter your value: ")
print(val)

You might also like