Python Programming Language
Python is a 3rd Generation programming language.
(1st – Machine Language
Highly dependent on the architecture
Every instruction was written in 1s and 0s
2nd – Assembly language
Highly dependent on the architecture
Uses words and 1s and 0s for instructions. This was easier for humans but the
computer cannot understand it fully.
The first type of translator comes to use.
Known as an assembler.
3rd –
How to do – Instructions have variables and handle memory locations
Independent of machine architecture.
Uses natural language like commands.
Eg : Pascal, C , C++, Java, Python, R
4th – What to do languages.
Eg: SQL
5th - AI based languages
NOT using binary logic
Simulation of human brain
Why Python is important?
It is beginner-friendly
Complete free
A versatile language ( Can create programs of a vast range)
Compatibility
Different IDEs to use with
IDE stands for Integrated Development Environment
It provides an environment to write, debug and execute the program
The default IDE for Python is IDLE
In addition to that, we can successfully use VS code, Jupyter, PyCharm etc…
Translators
The primary purpose of a translator is to convert the source code (Programming
code written by a programmer) to Machine code.
For third-generation languages, there are two types of translators as Compiler and
an Interpreter.
Characteristics of Python
Python is an Interpreted Language
Python is highly case-sensitive (lion , Lion and LION are three different words in
Python – They are sensitive to uppercase and lowercase)
Syntax (grammar of the programming language) is very clear
Comments in Python
Python comments start with # symbol
Comments are for the programmer and the programming language does not
interpret them.
Python has only single line comments
Input command in Python.
To get a user input we can use input() function in python.
In input() we give a prompt as a string for the user to understand what
he/she is supposed to enter.
Giving the prompt is not a must but it is a very important practice that
every programmer should follow
Make sure to give very clear instructions as your prompt.
Variables in Python
A variable is a named place in memory
It is a placeholder/ It is a temporary memory location
A variable can hold only one value at a time
The value inside a variable can be changed as a result of a calculation or a
user input.
Python variables are dynamic. We don’t have to declare the variables and
the data types of the values can also be different each time.
Identifier naming rules and conventions in Python.
An identifier is a name defined by the programmer.
Eg : Variable names, function names, enums etc.
Rules – Cannot break Get a syntax error
Conventions Good practices No syntax error but better to follow
Rules
1) Cannot use a keyword as an identifier name. Keywords are specially
reserved words that have a special meaning to the programming langue.
2) An identifier name must start with either an alphabetical letter (A-Z,a-z) or
underscore (_)
3) Rest of the characters can consist of alpha numeric characters (Alphabetical
letters and numbers) and/or underscore (_)
4) No any special symbol/character other than _ can be used anywhere in the
identifier name
5) Cannot keep spaces in between an identifier name (eg : “First name” is not
valid )
Variable naming conventions
1) Always give a meaningful identifier name
2) Use camelCase for variables and functions, PascalCase for class names
and even separate_by_underscore names.
Data types in Python
Data type is an attribute or classification of data .
It defines how the program will process data
(Like how each rank in the forces has a particular way of getting treated.)
There are simple and Compound data types in Python.
Numeric data types
(Integer data type – int)
(Real data represented by floating point data type – float)
(Complex data types – eg:5j)
String data type
Set of characters (any character sequence)
Given within either “ “ or ‘ ‘
Boolean data type
It is a subtype of integer in Python
Has only True or False literals.