Datatypes in Python 21 10 2024
Datatypes in Python 21 10 2024
Datatypes in Python 21 10 2024
In [ ]: --> Comments are the lines which we writing for understanding the code.
--> In Python If any line started with # Symbol then that particular line is a comment.
--> Comments will never be executed. Python will ignore all lines which are started with hash symbol.
30
--> In Python we don't have any syntax for Multiline Comments in Python.
--> Many Developers are using Triple Quotation for Making Multiline Comments.
--> We can manually start all lines of the comments with # Symbol.
--> For Few IDE's There is one shortcut to make multiline comments with # Symbol manually --> ctrl+backslash
30
--> However, it's generally recommended to use these sparingly and only for very short, self-explanatory comments.
In [ ]: a=10 #Value is 10
b=20 #Value is 20
print(a+b) #Addition of a and b
Print() in Python
In [ ]: --> print function is used to display the content/output to the screen.
In [5]: a=10
b=20
c=a+b
print(c)
30
In [6]: a=10
b=20
print(a,b)
10 20
Examples:
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'i
n', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
35
Variables in Python
In [ ]: --> Variables are used to store data.
--> We are storing data inside a variable such that we can use that variable in future.
10.5
--> Variable name can only contain Alphabets(Upper or Lower) , Digits and Underscore(_).
12total = 29
print(12total)
student roll = 99
In [19]: #Variable name can only contain Alphabets(Upper or Lower) , Digits and Underscore(_).
ca$h = 10
print(ca$h)
In [20]: #Variable name can only contain Alphabets(Upper or Lower) , Digits and Underscore(_).
ca_h = 10
print(ca_h)
10
In [22]: #Variable name can only contain Alphabets(Upper or Lower) , Digits and Underscore(_).
cah33 = 10
print(cah33)
10
Pratice Question
In [ ]: # Which of the variable names are valid and which are invalid?
type() in Python
In [ ]: --> This is a function which is used to return the datatype of a variable.
In [23]: x = 10
print(type(x))
<class 'int'>
In [24]: x = 10.5
print(type(x))
<class 'float'>
In [25]: x = 'Pratyush'
print(type(x))
<class 'str'>
Datatypes in Python
In [ ]: Data+Types --> Which kind of data we are using in our Python Programming.
--> In Python Programming we need not to give datatype of the variable instead of that we can
directly assign the value to a variable.Python will automatically detect which kind of data type we
are using in our Program.
Example:
Mobile_num = Number/Integer
Name = String/Alphabet/Characters
--> Whenever we are specifying any integer data then that number will never start 0
<class 'int'>
100
<class 'int'>
-100
<class 'int'>
-7837464636346
In [32]: num1 = 0
print(type(num1))
print(num1)
<class 'int'>
0
<class 'float'>
100.0
<class 'float'>
-100.0
<class 'float'>
0.0
<class 'float'>
123454.00002
Boolean Datatype
In [ ]: --> Boolean Datatypes are True or False.
<class 'bool'>
<class 'bool'>
In [41]: True+False+True+True
# 1 + 0 + 1 + 1
Out[41]: 3
In [42]: True*True*False
#1*1*0
Out[42]: 0
Input() Function
In [ ]: --> This Function is used to take input from the end user.
Enter a Number : 10
<class 'int'>
10
mass = int(input())
bmi = mass/(height*height)
print(bmi)
6
65
1.8055555555555556