Python
Python
Introduction
Python is a widely used general-purpose, high-level programming
language.
designed by Guido Van Rossum and developed by Python Software
Foundation.
Why to use Python?
Object-oriented - Python supports such concepts as polymorphism,
operation overloading and multiple inheritance.
Indentation - Unlike other languages like C, C++, or Java that uses {} to
mark blocks of code. Python uses indentation to group statements.
(usually 4 spaces) - Note: Don’t mix tabs and spaces.
Open-source - downloading python and installing python is free and easy.
Dynamic Typing - you don’t have to declare the datatype of a variable
when you declare it. Python figures it out at runtime.
Built-in types and tools
Library utilities
Third party utilities (for example Numpy, SciPy etc)
Automatic memory management.
Portable - Python runs virtually every major platform used today as long
as you have a compatible python interpreter installed.
Easy to use and learn
No intermediate compiling
Python programs are compiled automatically to an intermediate form
called byte code, which the interpreter reads.
This gives the python the development speed of an interpreter without
performance loss inherent in purely interpreted languages.
Interpreted Language - Python is processed at runtime by Python
interpreter line by line.
Straight forward syntax
Byte
Source Code Runtime
Digits 0-9
Special Symbols space +-/*\() [] {} // = != == <, > . '"'"",;:%!& # <= >= @_(underscore)
Whitespaces Blank space, tabs ( -->), carriage return (), newline formatted.
Other Characters Python can process all ASCII and Unicode part of data or literals
Identifiers
Identifiers are fundamental building blocks of a program and are used as
the general terminology for the names given to different parts of the
program like variables, objects, classes, functions, lists, dictionaries etc.
An identifier is an arbitrary long sequence of letters and digits
The first character must be a letter, the underscore (_) counts as a letter.
Upper and lowercase letters are different. All characters are significant
The digits 0 through 9 can be part of identifier except for the first
character.
Identifiers are unlimited in length. Case Sensitive.
An identifier cannot contain any special character except for underscore
(_)
An identifier must not be a keyword of python.
Keywords in Python
False await else import pass
number=6
if number > 5:
print(number**2)
print("Next Lines of Code")
The if-else statement checks the condition and executes the if block of code
when the condition is true and if the condition is false, then it will execute the
else block of code.
age = int(input("Enter the age: "))
if age >= 18:
print("Eligible to vote")
else:
print("Cannot vote")