Python Programming Basics
-
Upload
richardalexanderphilip -
Category
Education
-
view
130 -
download
7
Transcript of Python Programming Basics
Python Kashmira Rao Pramod Rajan Amarjeet Sav
Introduction History Features Installation Basic Datatypes Whitespace Control Statements
Overview
http://docs.python.org/
Python is pre-installed on most Unix systems, including Linux and MAC OS X
The pre-installed version may not be the most recent one (2.6.2 and 3.1.1 as of Sept 09)
Download from http://python.org/download/ Python provides two options
IDLE Command Line Interpreter
Installing
http://python.org/download/
Step #1
Step #2
Step #3
Step #4
Step #5
Indentation matters to code meaning◦Block structure indicated by indentation
First assignment to a variable creates it◦Variable types don’t need to be declared.◦Python figures out the variable types on its own.
Assignment operator is = and comparison operator is ==
To understand the code
For numbers + , - , * , / , % are as expected
◦Special use of + for string concatenation Logical operators are words (and, or, not) not symbols
The basic printing command is print
To understand the code (cont.)
You can assign values to multiple variable at the same time >>> x, y = 2, 3>>> x2>>> y3
This makes it easy to swap values>>> x, y = y, x
Assignments can be chained>>> a = b = x = 2
Assignment
The main statement used for selecting from alternative actions based on test results
It’s the primary selection tool in Python and represents the Logic process
If Statements
Simple If statement It takes the form of an if test
if <test>: <statement>
Simple If statement if 4>3: print (“it is true that 4>3”) if a==1: print (“true” ) a=10 if a==10:
print (“a=10”)
If Statement “login” example password=‘coolguru ‘
If password== input(“Enter your password :”): print(“You have logged in” )
If... else statement It takes the form of an if test, and
ends with an optional else block
if <test>: <statement1> else: <statement2>
If Statement “login” example password=‘coolguru ‘If password== input(“Enter your password :”): print(“You have logged in” )else: print(“ invalid password “)
If… else if … else statement It takes the form of an if test, followed
by one or more optional elif tests, and ends with an optional else block
if <test1>: <statement1> elif <test2>:
<statement2> else: <statement3>
If… else if … else statement examplenumber = 23guess = int(input('Enter an integer : '))
if guess == number:print ( 'Congratulations, you guessed it.‘)print ("(but you do not win any prizes!)“)
elif guess < number:print ('No, it is a little higher than that' )
else:print ('No, it is a little lower than that‘)
Applications of python Console applications Enterprise applications Web applications Mobile applications Office applications
Applications of python contd.. Used for Scripting. Developing games. Graphics and Animation Google search engine & Youtube Yahoo maps Financial applications
THANK YOU!!!