Top Banner
Python Kashmira Rao Pramod Rajan Amarjeet Sav
25

Python Programming Basics

Apr 13, 2017

Download

Education

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Python Programming Basics

Python Kashmira Rao Pramod Rajan Amarjeet Sav

Page 2: Python Programming Basics

Introduction History Features Installation Basic Datatypes Whitespace Control Statements

Overview

Page 3: Python Programming Basics

http://docs.python.org/

Page 4: Python Programming Basics

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

Page 5: Python Programming Basics

http://python.org/download/

Page 6: Python Programming Basics

Step #1

Page 7: Python Programming Basics

Step #2

Page 8: Python Programming Basics

Step #3

Page 9: Python Programming Basics
Page 10: Python Programming Basics

Step #4

Page 11: Python Programming Basics

Step #5

Page 12: Python Programming Basics

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

Page 13: Python Programming Basics

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.)

Page 14: Python Programming Basics

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

Page 15: Python Programming Basics

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

Page 16: Python Programming Basics

Simple If statement It takes the form of an if test

if <test>: <statement>

Page 17: Python Programming Basics

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”)

Page 18: Python Programming Basics

If Statement “login” example password=‘coolguru ‘

If password== input(“Enter your password :”): print(“You have logged in” )

Page 19: Python Programming Basics

If... else statement It takes the form of an if test, and

ends with an optional else block

if <test>: <statement1> else: <statement2>

Page 20: Python Programming Basics

If Statement “login” example password=‘coolguru ‘If password== input(“Enter your password :”): print(“You have logged in” )else: print(“ invalid password “)

Page 21: Python Programming Basics

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>

Page 22: Python Programming Basics

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‘)

Page 23: Python Programming Basics

Applications of python Console applications Enterprise applications Web applications Mobile applications Office applications

Page 24: Python Programming Basics

Applications of python contd.. Used for Scripting. Developing games. Graphics and Animation Google search engine & Youtube Yahoo maps Financial applications

Page 25: Python Programming Basics

THANK YOU!!!