Py Lecture-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

PYTHON 3.12.

LEARN WITH FUN


LECTURE-1
What is Python?

1. Python was developed by Guido van Rossum in the early 1990s and its latest version is
3.12.3, we can simply call it Python3.
2. Python is a high-level, general-purpose and very popular programming language.
3. Python programming language (latest Python 3) is being used in web development
and Machine Learning applications along with all cutting-edge technology in
Software Industry.
4. Python language is being used by almost all tech-giant companies like – Google,
Amazon, Facebook, Instagram, Dropbox, Uber… etc.
Setting up Python

● How to Download and Install Python on Windows Operating Systems?

Step 1: First and foremost step is to open a browser and type-:


https://www.python.org/downloads/windows/
Step 2: Underneath the Python Releases for Windows find the Latest
Python 3 Release – Python 3.12.3 (the latest stable release as of now is
Python 3.12.3).
Step 3: On this page move to Files and click on Windows x86-64
executable installer for 64-bit or Windows x86 executable installer
for 32-bit.

Steps to Install Python on Windows 10

● Run the Python Installer for how to install Python on the


Windows downloads folder.
● Make sure to mark Add Python 3.12.3 to PATH otherwise you
will have to do it explicitly. It will start installing Python on
Windows.
● After installation is complete click on Close.
● Python is installed. Now go to Windows and type IDLE.
● This is Python Interpreter also called Python Shell. I printed Hello
World, python is working smoothly.
● The three greater than >>> sign is called the Python command
prompt, where we write our program and with a single enter key,
it will give results so instantly.
Statement, Indentation and Comment in Python

● What is Statement in Python?


1. A Python statement is an instruction that the Python interpreter can execute.
2. There are different types of statements in Python language as Assignment statements,
Conditional statements, Looping statements, etc.

● Types of statements in Python?


1. Multi-Line Statements
2. Python Conditional and Loop Statements
a. Python If-else
b. Python for loop
c. Python while loop
d. Python try-except
e. Python with statement
3. Python Expression statements

a) Python pass statement


b) Python del statement
c) Python return statement
d) Python import statement
e) Python continue and
f) Python break statement
Declared using Continuation Character (\):
s = 1 + 2 + 3 + \

4 + 5 + 6 + \

7 + 8 + 9

Declared using parentheses () :


n = (1 * 2 * 3 + 7 + 8 + 9)

Declared using square brackets [] :


footballer = ['MESSI',

'NEYMAR',

'SUAREZ']
Declared using braces {} :
x = {1 + 2 + 3 + 4 + 5 + 6 +

7 + 8 + 9}

Declared using semicolons(;) :


flag = 2; ropes = 3; pole = 4
● What is Indentation in Python?

# Python indentation

A = 'abc'

if A == 'abc':

print('Logging on to python.org...')

else:

print('retype the URL.')

print('All set !')

Output

Logging on to python.org...

All set !
● What are Comments in Python?

1.Types of comments in Python-:

A. Single-line comment in Python

B. Multiline comment in Python

A. Single-line comment in Python

# This is a comment

# Print “Hello World” to console

print("Hello World")
B. Multiline comment in Python

# This is a comment

# This is second comment

# Print “Hello World” to console

print("Hello World")

"""This would be a multiline comment in Python that

spans several lines Here we are learning python3.12.3.

It is very interesting language for programming"""

print("Hello World")
Python | Set 2 (Variables, Expressions, Conditions and
Functions)

● Running your First Code in Python -:


Note- Python programs are not compiled, rather they are interpreted.

Program-:
print ("Hello World") # Notice that NO semi-colon is to be used
Variables in Python

1. Variables need not be declared first in python.


2. They can be used directly. Variables in python
are case-sensitive as most of the other
programming languages.
Example:

a=3

A=4

print (a)

print (A)
Expressions in Python

Arithmetic operations in python can be performed by using


arithmetic operators and some of the in-built functions.
a=2
b=3
c=a+b
print (c)
d=a*b
print (d)
Conditions in Python

Note:
Conditional output in python can be obtained by
using if-else and elif (else if) statements.
a=3
b=9
if b % a == 0 :
print ("b is divisible by a")
elif b + 1 == 10:
print ("Increment in b produces 10")
else:
print ("You are in else statement")
Functions in Python

1. A function in python is declared by the


keyword ‘def’ before the name of the function.
2. The return type of the function need not be
specified explicitly in python.
# Function for checking the divisibility

# Notice the indentation after function declaration

# and if and else statements

def checkDivisibility(a, b):

if a % b == 0 :

print ("a is divisible by b")

else:

print ("a is not divisible by b")

#Driver program to test the above function

checkDivisibility(4, 2)

You might also like