Comments,Indentation,Built-in Number Data types and Expressions in Python
1. Comments in Python
Comments are statements given by programmer for better understanding of programs.They are non executable statements.
Comments are of two types:
Single line comments
Single line comments are given by using ‘#’ symbol before writing statement.
EXAMPLE
#code to display itvoyagers
print('itvoyagers')
Multi line comments
Multi line comments are given by using opening and closing “”” “”” or ”’ ”’ symbol(triple quotes) before and after writing statements.
EXAMPLE
"""code to display itvoyagers and
to show example of multiline comments"""
print('itvoyagers')
Indentation in Python
Other programming languages uses opening and closing braces {} to define a block of statement.
This braces are replaced in python with indentation.
Indentation is important both IDLE and Script mode.
Indentation can be given as four spaces or one tab key.
EXAMPLE
for i in range(5):
print('itvoyagers')
else:
print("sorry range exceeded")
Note: in above example if indentation is not given then it may lead to indentation error
Built-in Number Datatypes in Python
Various classes like integer,floating point,long and complex indicates numeric values.
These can be defined as int, float, long and complex.
a. Integer (class int)
Integers can be positive or negative and are of unlimited size in Python.
EXAMPLE
143,-426
>>> 82-951+6
-863
>>> 1500087521651235122453210452104520+9
1500087521651235122453210452104529
>>> 2**945
297403381695556612559612499629980112026252040331878891811154371863188131432080874709033662899231270117959744758038594610090917049108981141558166116220478925156594168089491974788537281966859547374047839156470287441213549741375576017631419788069731616602409021090828782564753069762936832
>>> len(str(2**945))
285
Note: Above examples shows that integers are of unlimited size in python
b. Floating Point Numbers(class float)
Floating point numbers can be positive or negative which comes with decimal point and an optional exponent (e or E)
Floats are 64-bit double precision floating point numbers.
EXAMPLE
10.2,-9.6,3e4,-3E-4
>>> 5.42*-4e5
-2168000.0
>>> import random
>>> random.random()
0.5292462067367842
>>> 2.0**945
2.974033816955566e+284
c. Booleans (class bool)
Boolean values like True and False is given.
Here T and F are capitalized in boolean values.
In Python 0,None and empty value such as empty string “”,”,empty list [],empty dictionary {},empty tuple() etc are considered as False and anything apart from this is considered as True.
EXAMPLE
>>> True + 5
6
>>> False + 10
10
>>> True-False
1
>>> 50==50
True
>>> 50==80
False
d. Complex Numbers(class complex)
Complex numbers have two parts i.e. real and imaginary.
Real can be any integer and imaginary part is having ‘j’ as suffix
eg.(3+2j)
EXAMPLE
>>> 3+2j *8
(3+16j)
>>> 3+2j+5
(8+2j)
>>> 3+2j-2
(1+2j)
>>> k=9+5j
>>> k.real #to get real number
9.0
>>> k.imag #to get imaginary number
5.0
Expressions in Python
An expression is a combination of values,variables and operands.
EXAMPLE
>>> p=120
>>> p+60
180
>>> 12
12
>>> 8+(2-1)*9
17
>>>
For other python basics related posts:
Best post on programming language and its types – 1 |
Python Programming (Basics) – History & Features |
Python Programming (Basics)- Debugging & Types of errors |
Python Programming (Basics) – Variables, Values, Types & Keywords. |
Best post on built-in functions in python – 1 |
Python Programming (Basics) – Type Conversion |
Python Programming (Basics) – Comments,Indentation,Built-in Number Data types and Expressions |
Best post on IDLE & script mode in Python – 1 |
Python Programming (Basics)- Operators in Python |
Best post on Order of Operations – Python |
Simple and compound statements of python in easy way |
Best post on conditional statements in python – Part 1 |
Best post on conditional statements in python – Part 2 |
Best post on looping in python (for loop)-Part 1 |
Best post on looping in python (while loop)-Part 2 |
Best post on nested loop in python(looping) -Part 3 |
Best post on infinite loop in python(looping) -Part 4 |
Best post on control statements(break,continue,pass)-1 |
Best post on Function definition & calling in python -1 |
Easy flow of function execution,parameters,arguments-2 |
Easy fruitful & void function,return values,stack diagrams-3 |
Best post on types of function arguments in python- 4 |
Best post on recursive function, scope of variable-5 |
Best post on import and from statement in python – 1 |
Best post on modules and built-in modules math,random & time-2 |
Best post on user defined modules in python-3 |
Best post on string datatype in python – 1 |
Best post immutable string,string operations python-2 |
Best post on string methods in python – 3 |
Best post on list datatype in python – 1 |
Best post on mutable list, list operations python – 2 |
Best post on List methods in python – 3 |
Best post on dictionary datatype in python – 1 |
Best post on dictionary methods and operations-2 |
Best post on tuple datatype in python – 1 |
Best post on tuple operations and immutable tuple- 2 |
Best post on tuple methods and built-in functions-3 |
17 -Python program to demonstrate Button in tkinter and its event in easy way |
New posts coming soon....... |
For other advanced python related posts:
File Systems and File Handling in Python |
Types of file modes and attributes of file object in Python |
How to read,write and append in a file in python? |
Remaining file methods in Python |
File Positions in Python |
Directory in Python and its methods |
Iterator and Iterables in Python |
Exceptions in Python |
Exception Handling in Python (Part I) |
Exception Handling in Python (Part II) |
Regular Expressions |
Metacharacters or Regular Expression Patterns |
Functions in 're' module(Part I)- Match vs Search |
Functions in 're' module(Part II)-findall(), split(), sub() |
Flags for regular expressions(Modifiers) |
GUI programming in Python and Python GUI Library |
What is Tkinter ? |
Layout Manager (Geometry Manager) in Python |
Events and Bindings in Python along with Widget configuration and styling |
Fonts Names, Font Descriptors, System Fonts, Text formatting, Borders, Relief Styles in Python |
Best post:Dimensions, Anchors, Bitmaps & Cursors in Python |
Canvas widget of tkinter module – Python |
Widgets in tkinter module – Python |
Label, Text, Entry & Message Widget in Python |
Button, Checkbutton & Radiobutton Widget in Python |
Best post on Menu and Menubutton Widget of tkinter |
Best post- Listbox and Scrollbar(Slider) Widget-Python |
Best post on Frame Widget of tkinter in Python |
Best post: message box widget and its methods |
Best post- LabelFrame, Toplevel, PanedWindow widgets |
Best post on Spinbox and Scale Widget in Python |
Best post : Database connectivity in Python (Part 1) |
Best post : Database Connectivity in Python (Part 2) |
Best post on Create and Insert query : Python + MySQL |
Best post on Select Query to Search & Read: Python + MySQL-4 |
Best post on Update query and Delete query : Python + MySQL-4 |
New posts coming soon....... |