0% found this document useful (0 votes)
8 views4 pages

Python Notes by Ankush-Chap03-FirstProgram

This document is a beginner's tutorial on Python, covering the basics such as printing 'Hello World', using Python as a calculator, and running Python code. It explains the execution flow of Python code, including lexical analysis, syntax parsing, bytecode generation, and execution by the Python Virtual Machine. Additionally, it compares interpreters and compilers, highlighting their differences in execution speed and debugging ease.

Uploaded by

paidpdfnotes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Python Notes by Ankush-Chap03-FirstProgram

This document is a beginner's tutorial on Python, covering the basics such as printing 'Hello World', using Python as a calculator, and running Python code. It explains the execution flow of Python code, including lexical analysis, syntax parsing, bytecode generation, and execution by the Python Virtual Machine. Additionally, it compares interpreters and compilers, highlighting their differences in execution speed and debugging ease.

Uploaded by

paidpdfnotes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PYTHON TUTORIAL FOR BEGINNERS

Chapter - 03

First Python Program


• Print- Hello World!
• Python As a Calculator
• Running the Python code
• Python Execution Steps
• Interpreter v/s Compiler

First Python Program - Hello World


Printing "Hello World" as the first program in Python.
print is a keyword word that has special meaning for Python.
It means, "Display what’s inside the parentheses."
print("Hello World")

Instructor = "Rishabh Mishra"


print("flython by", Instructor, sep="-")

Python As a Calculator
Python can be used as a powerful calculator for performing a wide range of
arithmetic operations.
2+5 add two numbers
print(10/5) divide two numbers

print sum of two numbers


a = 2
b = 5
print(a+b)

P y thon No te s by Ankush
Comments: Comments are used to annotate codes, and they are not
interpreted by Python. It starts with the hash character #
Comments are used as notes or short descriptions along with the code to increase
its readability.

Running the Python Code


• Create a new text file and inside it write – print(“Welcome to the Python
Course by Rishabh Mishra”)
• Save file with extension .py – firstcode.py
• Open command prompt on windows (or Terminal on MacOS)
• Enter the location where firstcode.py file is saved – cd downloads
• Finally run the file as – python firstcode.py

Python Execution Flow

P y thon No te s by Ris habh Mish ra


Python Code Execution Steps

1. Lexical Analysis: The interpreter breaks down the code into smaller parts
called tokens, identifying words, numbers, symbols, and punctuation.
2. Syntax Parsing: It checks the structure of the code to ensure it follows the
rules of Python syntax. If there are any errors, like missing parentheses or
incorrect indentation, it stops and shows a SyntaxError.
3. Bytecode Generation: Once the code is validated, the interpreter translates
it into a simpler set of instructions called bytecode. This bytecode is easier
for the computer to understand and execute.
4. Execution by PVM: The Python Virtual Machine (PVM) takes the bytecode
and runs it step by step. It follows the instructions and performs calculations,
assigns values to variables, and executes functions.
5. Error Handling and Output: If there are any errors during execution, like
trying to divide by zero or accessing a variable that doesn't exist, the
interpreter raises an exception. If the code runs without errors, it displays
any output, such as printed messages or returned values, to the user.

Python Syntax

The syntax of the Python programming language, is the set of rules that defines
how a Python program will be written and interpreted (by both the runtime system
& by human readers).
my_name = "Madhav" ⬛

my_name = Madhav +
Use quotes "" for strings in flython

P y thon No te s by Ris habh Mish ra


Interpreter vs Compiler

Interpreter Compiler
An interpreter translates and A compiler translates the entire code
executes a source code line by line into machine code before the
as the code runs. program runs.

Execution: Line by line. Execution: Entire program at once.

Speed: Faster execution because it


Speed: Slower execution because
translates the entire program at once.
it translates each line on the fly.
Debugging: Easier to debug as it Debugging: Harder to debug
stops at the first error encountered. because errors are reported after the
entire code is compiled
Examples: Python, Ruby,
Examples: C, C++, Java, and Go.
JavaScript, and PHP.

Python Tutorial Playlist:

P y thon No te s by Ris habh Mish ra

You might also like