By: Archana Shukla and Rajesh Shukla
Punctuators
Punctuators are symbols that are used in programming languages to organize sentence structures and indicate the rhythm and emphasis of expressions, statements and program structure.
Most common punctuators of Python language are : ‘, “, #, \, (), [], {}, @, :, `, =
Variables
Variables represent labeled storage location for data values. A variable is created the moment you first assign a value to it.
Example :- x = 8
y = “hello”
print(x)
print(y)
Variables do not need to be declared with any particular type and can even change type after they have been set. This is called Dynamic typing.
For example :
x = 2 # x is of type int
x = “hello” # x is now of type str
print(x)
Assigning Value to Multiple Variables:- Python allows you to assign values to multiple variables in one line:
Example:
x, y, z = 10, 20, 30
print(x)
print(y)
print(z)
And you can assign the same value to multiple variables in one line:
Example:
x = y = z = 10
print(x)
print(y)
print(z)
Data Types
Variables can store data of different types, and different types can do different things. Python has the following buit-in core data types : Numbers, none, sequences, sets, mappings
Data types for numbers
There are three numeric data types in Python:
Integers
Floating point numbers
Complex numbers
Variables of numeric types are created when you assign a value to them:
x = 2 # int
y = 3.5 # float
z = 2j # complex
Note: To verify the type of any object in Python, we use the type() function:
print(type(x))
print(type(y))
print(type(z))
None
This is a special data type with unidentified value. It signifies the absence of value in a situation, represented by none.
Sequence
A sequence is an ordered collection of items , indexed by integers( both +ve and –ve). The three types of sequence data types are Strings, Lists, Tuples.
Sets
Set is an unordered collection of values of any type with no duplicate entry. It is immutable.
Mappings
This data types is unordered and immutable. Dictionaries are the example of mapping datatype. A dictionary is combination of a key and a value. Values are accessed using keys from the dictionary. Dictionary is enclosed in curly brackets{}.