Python #3 Variables and Values

 Variables and Values

What is variable?
Variable is object in which a value is assigned. There are 4 types of variables-
1. Strings
2. Integers
3. Floats
4. Booleans

Strings
Strings are a piece of data in form of text and number. Strings and written inside "", '' and ''' '''. Variables can be printed using their variable name.
Lets make a variable and understand it-


string = "This is a variable."
print(string)



Here string is our variable. It is containing a string, the value of string is "This is a variable". When the print command is executed it prints the value of string variable.


If you want to check type of variable of particular variable then use type() function, this is a built-in function by python this shows the type of variable in python by following keywords-


<class 'str'> = String
<class 'int'> = Integer
<class 'float'> = Float(Decimal)
<class 'bool'> = Boolean


Input


string = "This is a variable."
print(type(string))



Output


Here type() function shows the class or type of variable as str which means string.

Integer

These are also same as strings, but it only contains numeric values without any points(".") or else it would be considered as a Float or Decimal. These are not in "",'' or ''' ''' else they would be classified as strings.



integer = 4
float = 5.3
print(type(integer))
print(type(float))


Output



Booleans
Booleans are just of two type "True" and "False".

Input


Boolean = True
print(type(Boolean))


Output





Post a Comment

3 Comments

  1. https://shorturl.at/rvT58

    ReplyDelete
    Replies
    1. https://mega.nz/file/p2hHzKZA#VSyRSrZbrQEbYTyOkxmuegyiPr7JDr17Z7Uw6JmDTKE

      Delete
  2. https://lichess.org/7VRGoGBq

    ReplyDelete