python 3 tutorial for beginners Tutorial

Python Scalar Data Type

In Python programming language we following Scalar Data Type
Integer: Store simple numbers. There is no limit for the length of integer literals apart from what can be stored in available memory.
Float: Store decimal number.
Bool: For boolean.
None: empty or null.
Imaginary or Complex: Complex number.

How to define an Integer or float variables in Python?

Defining variables in Python is simple. type your variable name and initialize with its value. 

Following are some example of number variables

year = 2018
print(year) # 2018
gravity = 9.807
print(gravity) #9.807

If we are going to perform any calculation between int and float. The result is going to promote to float.

print(year+gravity) # 2027.807
print(year-gravity) # 2008.193
print(year*gravity) # 19790.526
print(year/gravity) # 205.77138778423574

For large numbers, you can use scientific notations

print(1e15) # It is equals to 1000000000000000.00
print(1e-4) # It is equals to 0.0001

Python 3 Undersocres in Number

For large numbers, you can use underscore. Underscores are ignored for determining the numeric value.
Example: 100_000_000_000
Output: 100000000000

Boolean: Following are some examples, for boolean variables


Note: Both True and False must start with capital letter. Following the variable declaration, is going to fail. 

None in Python.None is null or empty in Python.

empty_none = None
print(empty_none) # None 

You can check if any variable is None using "is"
print(empty_none is None) # True

An imaginary number is a complex number that can be written as a real number multiplied by the imaginary unit i. But in python we use j instead of i.

complex_number = 1+8j

We can also use binary, octal and hexadecimal numbers

binaryNumber = 0b10
print(binaryNumber) # 2 
octalNumber = 0o10
print(octalNumber) # 8
hexaDecimalNumber = 0x10
print(hexaDecimalNumber) # 16

Multiple Assignments

In python, we like most of the other languages, we can assign a single value to multiple variables. Following example for assigning a single same value to multiple variables.
In the above example, we created three different variables but same value "1"

But what if we need to define multiple variables in the single line you can use below syntax. 
one, two, three = 1,2,3
In the above example, we declare three variables and assign values for all three variables.
python_course_price , author, url = 0,"Mayank", ''
In the last example datatype for all three variables are same. But in the above example, we have 1 Integer Variable and two string variables.


Leave A Comment

Please login to post your valuable comments.