Variables are used for various data. In simple words, the variable is like a container that is
used for storing data.
Rules for variable name:-
1. Variable names can be written with the help of (A to Z), ( a to z), ( o to 9), ( _ ).
Example:- Number1= (it is valid),
Number@1= (it is not valid)
2. Variable names do not start with a number.
Example:- Num1= (it is valid),
1Num= (it is not valid)
3. Variable name does not contain white space.
Example:- First name= (it is not valid)
First_name= (it is valid)
4. Keywords can not be used as variable names.
Example:- if= (it is not valid)
Keyword
The keyword is those words that are predefined in Python. It is also known
as the reserved word. There are 35 keywords in Python which are the following:-
‘False’, ‘None’, ‘True’, ‘and’, ‘as’, ‘assert’, ‘async’, ‘await’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘nonlocal’, ‘not’, ‘or’, ‘pass’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’
Notes:- You don’t need to cram it. Just require to type the following command to
get the list of Python keywords.
Code:-
import keyword
print(keyword. Kwlist)
Data Type
The data type is used to define which type of value variable will contain.
There are 10 main data types in python
1. INT
Any number which does not have any decimal value
Example: – 56, 789, -66, etc.
2. FLOAT
Any number which must contain the decimal value
Example: -78.67, 789.76, 7.0
3. COMPLEX
It concedes only one string parameter. If the opening argument is a string type, it will not acknowledge assigning the second argument. It produces an error if we pass the second parameter.It contains “(5+7j)” kind of number
4. BOOL
Boolean contains either “True” or “False”
5. STR
The string is a character or a combination of characters. It periodically writes in (‘ ‘), (“ “),
(‘’’ ‘’’), (“”” “””).
Examples: “python”, ‘Dreamer Infotech’, etc.
6. LIST
It is a collection of heterogeneous data types. It is uncertain or unreliable. It is defined in “ [ ] “.
Example: [“Python”, 56.32, 55, True, (6+3j)]
7. RANGE
It is used to generate a sequence of numbers over time. It is defined as a range(start, end, step-size)
The default step size is 1.
Example: range(1,10,2), range(1,10)
8. TUPLE
It is similar to the list. But it is immutable or unchangeable in nature. It is defined in “ ( )”.
Example: (4, 5.3, “Python”, True)
9. DICT
The dictionary is a collection of keys and their values. The key must be unique but
value can be duplicated.
It is defined by {“key”: “value”}.
Example: {“Name”:” Nitesh”, “Age”:23}
10. SET
A Set is also a collection of heterogeneous elements. Set items are unordered,
unchangeable, and do not allow duplicate values.
It is defined by “ set()”.
Example: set(34,6.8,True, “Python”)
How to check the Datatype of a variable
Code:-
Number=45.67
print(type(Number))
Output:-
Basic Inbuilt Function
1. print(): print() function is used to display the output as a result.
2. input(): input() function is used to accept input from the user.
3. type(): type() function is used to check the data type of the variable.
Join Dreamer Infotech to Learn Python Training Course in Faridabad.