Programming With Python CHAPTER 01 (1)
Programming With Python CHAPTER 01 (1)
COURSE OUTCOMES
Install the given python IDE and editor.
When you run a Python script, Python automatically compiles it into bytecode. This bytecode is stored in .pyc files
in a __pycache__ directory.
Python Virtual Machine (PVM) is a program which provides programming environment. The role of PVM is to
convert the byte code instructions into machine code so the computer can execute those machine code instructions
and display the output.
Interpreter converts the byte code into machine code and sends that machine code to the computer processor for
execution.
Internal Working of Python
How is Python Source Code Converted into Executable Code
The Python source code goes through the following to generate an executable code
•Step 1: The Python compiler reads a Python source code or instruction in the code editor. In this first stage, the execution of
the code starts.
•Step 2: After writing Python code it is then saved as a .py file in our system. In this, there are instructions written by a Python
script for the system.
•Step 3: In this the compilation stage comes in which source code is converted into a byte code. Python compiler also checks
the syntax error in this step and generates a .pyc file.
•Step 4: Byte code that is .pyc file is then sent to the Python Virtual Machine(PVM) which is the Python interpreter. PVM
converts the Python byte code into machine-executable code and in this interpreter reads and executes the given file line by
line. If an error occurs during this interpretation then the conversion is halted with an error message.
•Step 5: Within the PVM the bytecode is converted into machine code that is the binary language consisting of 0’s and 1’s.
This binary language is only understandable by the CPU of the system as it is highly optimized for the machine code.
•Step 6: In the last step, the final execution occurs where the CPU executes the machine code and the final desired output will
come as according to your program.
Installation of Python
Installation of Anaconda
Learn to Use Google Colab
PYTHON BUILDING BLOCKS
• In most of the programming language, indentation • Since whitespaces are used for indentation, if the code
is used to properly structure the code. In Python, is large and indentation is corrupted then it’s really
it’s used for grouping, making the code tedious to fix it. It happens mostly in copying the code
from online sources, Word document, or PDF files.
automatically beautiful.
• Most of the popular programming languages use braces
• Python indentation rules are very simple. Most of
for indentation, so anybody coming from other side of
the Python IDEs automatically indent the code for
the development world finds it hard at first to adjust to
you, so it’s very easy to write the properly
the idea of using whitespaces for the indentation.
indented code.
PROGRAMMING WITH PYTHON
RESOURCE PERSON: Ms SANGEETAWANKHADE
VARIABLES
◾ A variable can be considered a storage container for data.
◾ Every variable will have a name.
◾ A Programmer should always choose a meaningful name for
their variable.
◾ Rules for Variable Names:
• A variable name can only start with a Letter or the
Underscore ( _ ) character.
• A variable name cannot start with a number or digit.
• A variable name can only contains the Alpha-Numeric
characters and Underscore character( like A-z , 0-9 and
_ ).
• The Variable names are case – sensitive ( car, Car and
CAR are three different variables ).
◾ You can’t use special characters like !, @, #, $, % etc. in
variable name.
COMMENTS
◾ Using comments in programs makes our code more understandable. It makes the program
more readable which helps us remember why certain blocks of code were written.
◾ Other than that, comments can also be used to ignore some code while testing other blocks of
code. This offers a simple way to prevent the execution of some lines or write a quick
pseudo-code for the program.
PYTHON DATA
TYPES
NUMBER(INTEGER)
◾ Int
◾ (signed integers like 13, 2, 29, etc.)
◾ Long
◾ (long integers used for a higher range of values like 90809080L, -0x192929L, etc.)
◾ Float
◾ (float is used for floating-point numbers like 1.9, 9.902, 15.2, etc.)
◾ complex
◾ (complex numbers like 2.14j, 2.0 + 2.3j, etc.)
STRING
◾ The string can be defined as the sequence of characters represented in the quotation(“ ”) marks.
◾ We will use single, double, or triple quotes to define a string in Python.
◾ Single Quote string:
◾ String handling in python is a straight forward task since there are various inbuilt functions and operators
provided.
◾ For Example:
◾ •A=‘Fireblaze’
Here A is having a single word Fireblaze so here we pass only single Quote.
• B=”Kartik’s friend”
Here B is having the ‘s after a Kartik if we use a single quote the word will phrase will end there for we use
double quote.
• C= ”’His friend’s,”laptop is good””’
Here we use a double quote inside the statement for that we have to pass a triple quote in such situation.
THE FOLLOWING EXAMPLE SHOWS THE STRING HANDLING IN
PYTHON
str1=’DataScience’
str2= ‘Python’
print(str1[0:2])
print(str1[4])
print(str1*2)
print(str1+str2)
LIST
◾ print (l)
◾ print (l + l)
A tuple is similar to the list in many ways.
TUPLE
The items of the tuple are separated with a comma (,)
and enclosed in parentheses ().
QUESTIONS?
Thank You…!!!