Python Variable and Data Type 2 | Learn With Pirates
Chapter 2: Python variable and Data Type
Variable is the name of the memory location of the program element.
Example For
a = 77 #Integer
b = "Pirates" #String
c = 17.0 #float
Data Types
There some data types of python have listed below.
Integer
String
Float
Booleans
None
python is intelligent for identity which data type is for what
like,
if you write
a = 77 #identifies as Integer
b = "Pirates" #identifies as String
c = 17.0 #identifies as float
There are some Rule to define a variable
- Variable Content alphanumeric, alphabet, underscore
- a variable name can only start with alphabets and underscore
- a variable name can not start with numbers
- space can not contain a variable name.
Operates in Python
In python, we have some common operators.
#arithmetic operators +, -, *, %, /,etc.
#assignment operates =, +=, -=, etc.
#comparison operator ==, !=, <, >, etc.
#logical operator and, or, not.
type() Function
type() function is use for find data type for variable.
a= 50
b= "PIrates"
c= 30.5
print(type(a))
print(type(b))
print(type(c))
Output
<class 'int'>
<class 'str'>
<class 'float'>
Type Casting
numeric variable is converteble like
a= 50
b= "50"
c= 50.0
print(type(a))
print(type(b))
print(type(c))
Output
<class 'int'>
<class 'str'>
<class 'float'>
input() Function
input() function is used for taking input from the user. every input gives use is by default convert into a string at the output.
a = input("enter a date of your birthdate: ")
print("your birthdate is " +a)
Output
enter a date of your birthdate: 4
your birthdate is 4
NOTE: The user input is a convert to string even you enter the number value.
Read Chapter 3:
Read Chapter 1:
Termination:
If you Like this tutorial please share with your friend and family. I make an amazing tutorial in this blog. If you have any queries and question ask me in the comment section below.
No comments
Post a Comment