0% found this document useful (0 votes)
25 views

Python Programming

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Python Programming

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Python

programming

Muhammad Ashfaq Najar


What we will learn today about python.

> History
> Introduction
> Features
> Package
Components
History
 Python was developed by Guido van Rossum in the late
eighties and early nineties (1991)at the National Research
Institute for Mathematics and Computer Science in the
Netherlands.
 Guido van Rossum was reading the script of a popular BBC
comedy series "Monty Python's Flying Circus“ and hence…..
 Python is derived from many other languages, including ABC,
Modula-3, C, C++, Algol-68, SmallTalk, and Unix shell and
other scripting languages.
 Python is copyrighted, Like Perl, Python source code is now
available under the GNU General Public License (GPL).
Introduction

Python is a popular programming language.

It is used for:
• Web development (server-side),
• Software development,
• Mathematics,
• System scripting. (Server Management, Security
etc.)
What can Python do?

• Python can be used on a server to create web applications.


• Python can be used alongside software to create workflows.
• Python can connect to database systems. It can also read and
modify files.
• Python can be used to handle big data and perform complex
mathematics.
• Python can be used for rapid prototyping, or for production-
ready software development.
Why Python?

• Python works on different platforms (Windows, Mac, Linux,


Raspberry Pi, etc.).
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can be
very quick.
• Python can be treated in a procedural way, an object-oriented way or
a functional way.
Features

 Easy to Code.
 Open Source & Free Software.
 Support for GUI.
 Object-Oriented Methodology.
 High-Level Language.
 Highly Portable Language.
 Integrated by Nature.
 Extremely Dynamic
Python Philosophy

 Coherence
 not hard to read, write and maintain
 Power
 Scope
 rapid development + large systems
 Objects
 Integration
 hybrid systems
Package Components

 Syntax
 Variables
 Operators
 Data Types
 Strings
 Functions
 Arrays
 Lists
 Etc.
Python Syntax

Python syntax can be executed by writing directly in the


Command Line:

>>> print("Hello, World!")


Hello, World!
Python Indentation
 Indentation refers to the spaces at the beginning of
a code line.
 The indentation in Python is very important.
 Python uses indentation to indicate a block of code.

if 5 > 2:
print("Five is greater than two!") Without Error
if 5 > 2:
print("Five is greater than two!") Error
Variables
Variables are containers for storing data values.
Creating Variables
 Python has no command for declaring a variable.
 A variable is created the moment you first assign a value to it .

Example 1
x=5
y = “ABC"
print(x)
print(y) Output 5 ABC

Example 2
x=4 # x is of type int Output only ABC
x = “ABC" # x is now of type str
print(x)
Variable Names
 A variable can have a short name (like x and y) or a more descriptive
name (age, carname, total_volume). Rules for Python variables:A
variable name must start with a letter or the underscore character
 A variable name cannot start with a number
 A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
 Variable names are case-sensitive (age, Age and AGE are three
different variables)
 A variable name cannot be any of the Python keywords.
Example Example
Legal variable names: Illegal variable
names:
myvar = "John"
my_var = "John" 2myvar = "John"
_my_var = "John" my-var = "John"
myVar = "John" my var = "John"
MYVAR = "John"
myvar2 = "John"
Assign Multiple Values
Python allows you to assign values to multiple variables in one line:

Example
 x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)

 x = "Python"
y = "is"
z = "awesome"
print(x, y, z)
Operators

Operators are used to perform operations on variables


and values.

Example
print(10 + 5)
Output = 15
Python divides the operators in the following groups:
 Arithmetic operators
 Assignment operators
 Comparison operators
 Logical operators
 Identity operators
 Membership operators
 Bitwise operators
Arithmetic Operators
Operator Name Example

+ Addition x+y

- Subtraction x-y

* Multiplication x*y

/ Division x/y

% Modulus x%y

** Exponentiation x ** y

// Floor division x // y
Assignment Operators
Operator Example Same As
= x=5 x=5
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
&= x &= 3 x=x&3
|= x |= 3 x=x|3
^= x ^= 3 x=x^3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3
:= print(x := 3) x=3
print(x)
Logical Operators
Operator Description Example

and Returns True if both x < 5 and x < 10


statements are true

or Returns True if one of x < 5 or x < 4


the statements is true

not Reverse the result, not(x < 5 and x <


returns False if the 10)
result is true
Comparison Operators
Operator Name Example

== Equal x == y

!= Not equal x != y

> Greater than x>y

< Less than x<y

>= Greater than or equal x >= y


to

<= Less than or equal to x <= y


Operator Precedence
Operator precedence describes the order in which operations are performed.
 Example
Parentheses has the highest precedence, meaning that expressions inside
parentheses must be evaluated first:
print((6 + 3) - (6 + 3))

Operator Description
() Parentheses
** Exponentiation
+x -x ~x Unary plus, unary minus, and bitwise NOT
* / // % Multiplication, division, floor division, and
modulus
+ - Addition and subtraction
<< >> Bitwise left and right shifts
Thank

You might also like