Prognoz Technologies Pvt Ltd Empowering through Skill Development

  • Slides: 41
Download presentation
Prognoz Technologies Pvt. Ltd Empowering through Skill Development Python Fundamentals-I Version 1. 0

Prognoz Technologies Pvt. Ltd Empowering through Skill Development Python Fundamentals-I Version 1. 0

v Introduction to Python? v Features of Python v History Of Python v Version

v Introduction to Python? v Features of Python v History Of Python v Version of Python v Python Applications v Setting Path in Python v Variables v Tokens & Comments v Tokens-Keywords v Tokens-Identifiers v Tokens-Literals v Tokens-Operators v Comments © Prognoz Technologies Pvt. Ltd. Version 1. 0

Introduction to Python? ØPython is an interpreted, object-oriented, programming language with dynamic semantics. high-level

Introduction to Python? ØPython is an interpreted, object-oriented, programming language with dynamic semantics. high-level ØIts high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. ØPython's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. ØPython supports modules and packages, which encourages program modularity and code reuse. ØThe Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed. © Prognoz Technologies Pvt. Ltd. Version 1. 0

Features of Python ØEasy to Use – Programmer- Friendly Language ØExpressive Language- Code is

Features of Python ØEasy to Use – Programmer- Friendly Language ØExpressive Language- Code is Easily Understandable ØInterpreted Language- Makes Easy Debugging ØCross-platform language- Run on different platform and it is portable. ØFree and Open Source ØObject Oriented Language- Concepts of class and objects comes into existence ØExtensible-C/C++ can be used to compile the code and thus it can be used further in python code ØLarge Standard Library- Large and Broad Library ØGUI Programming- Used to create Graphical User Interfaces ØIntegrated- Can be integrated with all level of high level languages © Prognoz Technologies Pvt. Ltd. Version 1. 0

History Of Python ØPython laid its foundation in the late 1980 s. ØThe implementation

History Of Python ØPython laid its foundation in the late 1980 s. ØThe implementation of Python was started in the December 1989 by Guido Van Rossum at CWI in Netherland. ØABC programming language is said to be the predecessor of Python language which was capable of Exception Handling and interfacing with Amoeba Operating System. ØPython is influenced by programming üABC language. üModula-3 © Prognoz Technologies Pvt. Ltd. Version 1. 0 languages like:

Version of Python A list of python versions with its released date is given

Version of Python A list of python versions with its released date is given below. Python Version Released Date Python 1. 0 January 1994 Python 1. 5 December 31, 1997 Python 1. 6 September 5, 2000 Python 2. 0 October 16, 2000 Python 2. 1 April 17, 2001 Python 2. 2 December 21, 2001 Python 2. 3 July 29, 2003 Python 2. 4 November 30, 2004 Python 2. 5 September 19, 2006 Python 2. 6 October 1, 2008 Python 2. 7 July 3, 2010 Python 3. 0 December 3, 2008 Python 3. 1 June 27, 2009 Python 3. 2 February 20, 2011 Python 3. 3 September 29, 2012 © Prognoz Technologies Pvt. Ltd. Version 1. 0

Version of Python(Cont. ) Python programming language is being updated regularly with new features

Version of Python(Cont. ) Python programming language is being updated regularly with new features and support. There a lot of updating in python versions, started from 1994 to current date. For Other Platforms: Ø“Python” or “CPython” is written in C/C++. Ø“Jython” is written in Java for the JVM. Ø“Iron. Python” is written in C# for the. Net environment © Prognoz Technologies Pvt. Ltd. Version 1. 0

Python Applications Python as a whole can be used in any sphere of development.

Python Applications Python as a whole can be used in any sphere of development. Python is used to create: 1) 2) 3) 4) 5) 6) Console Based Application Audio & Video Based Application 3 D CAD Application Web Applications Enterprise Applications for images © Prognoz Technologies Pvt. Ltd. Version 1. 0

Setting Path in Python Before starting working with Python, a specific path is to

Setting Path in Python Before starting working with Python, a specific path is to set. • Your Python program and executable code can reside in any directory of your system, therefore Operating System provides a specific search path that index the directories Operating System should search for executable code. • The Path is set in the Environment Variable of My Computer properties: • To set path follow the steps: • Right click on My Computer ->Properties ->Advanced System setting ->Environment Variable ->New • In Variable name write path and in Variable value copy path up to C: //Python(i. e. , path where Python is installed). Click Ok >Ok. © Prognoz Technologies Pvt. Ltd. Version 1. 0

Setting Path in Python(Cont. . ) Path will be set for executing Python programs.

Setting Path in Python(Cont. . ) Path will be set for executing Python programs. 1. Right click on My Computer and click on properties. 2. Click on Advanced System settings © Prognoz Technologies Pvt. Ltd. Version 1. 0

Setting Path in Python(Cont. . ) 3. Click on Environment Variable tab. © Prognoz

Setting Path in Python(Cont. . ) 3. Click on Environment Variable tab. © Prognoz Technologies Pvt. Ltd. Version 1. 0

Setting Path in Python(Cont. . ) 4. Click on new tab of user variables.

Setting Path in Python(Cont. . ) 4. Click on new tab of user variables. © Prognoz Technologies Pvt. Ltd. Version 1. 0

Setting Path in Python(Cont. . ) 5. Click on new tab of user variables.

Setting Path in Python(Cont. . ) 5. Click on new tab of user variables. © Prognoz Technologies Pvt. Ltd. Version 1. 0

Setting Path in Python(Cont. . ) 6. Copy the path of Python folder ©

Setting Path in Python(Cont. . ) 6. Copy the path of Python folder © Prognoz Technologies Pvt. Ltd. Version 1. 0

Setting Path in Python(Cont. . ) 7. Paste path of Python in variable value.

Setting Path in Python(Cont. . ) 7. Paste path of Python in variable value. 8. Click on Ok button: © Prognoz Technologies Pvt. Ltd. Version 1. 0

Setting Path in Python(Cont. . ) 9. Click on Ok button: © Prognoz Technologies

Setting Path in Python(Cont. . ) 9. Click on Ok button: © Prognoz Technologies Pvt. Ltd. Version 1. 0

 © Prognoz Technologies Pvt. Ltd. Version 1. 0

© Prognoz Technologies Pvt. Ltd. Version 1. 0

Python Variables ØVariable is a name of the memory location where data is stored.

Python Variables ØVariable is a name of the memory location where data is stored. Once a variable is stored that means a space is allocated in memory. Assigning value to variables: © Prognoz Technologies Pvt. Ltd. Version 1. 0

Python Variables(Cont. ) Multiple Assignment: Multiple assignment can be done in Python at a

Python Variables(Cont. ) Multiple Assignment: Multiple assignment can be done in Python at a time. 2 ways to assign values in python: 1. Assigning single value to multiple variables Example: x=y=z=50 print x print y print z 2. Assigning multiple value to multiple variables Example: a, b, c=5, 10, 15 print a print b print c © Prognoz Technologies Pvt. Ltd. Version 1. 0

 © Prognoz Technologies Pvt. Ltd. Version 1. 0

© Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments This section contains the basic fundamentals of Python like : i)Tokens

Tokens & Comments This section contains the basic fundamentals of Python like : i)Tokens and their types. ii) Comments a)Tokens: ØTokens can be defined as a punctuator mark, reserved words and each individual word in a statement. ØToken is the smallest unit inside the given program. There are following tokens in Python: 1. 2. 3. 4. Keywords. Identifiers. Literals. Operators. © Prognoz Technologies Pvt. Ltd. Version 1. 0

 © Prognoz Technologies Pvt. Ltd. Version 1. 0

© Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Keywords ØKeywords are special reserved words which convey

Tokens & Comments(Cont. . ) Python Keywords ØKeywords are special reserved words which convey a special meaning to the compiler/interpreter. ØEach keyword have a special meaning and a specific operation. True False None and as asset def class continue break else finally elif del except global for if from import raise try or return pass nonlocal in not is lambda © Prognoz Technologies Pvt. Ltd. Version 1. 0

 © Prognoz Technologies Pvt. Ltd. Version 1. 0

© Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Identifiers: ØIdentifiers are the names given to the

Tokens & Comments(Cont. . ) Python Identifiers: ØIdentifiers are the names given to the fundamental building blocks in a program. ØThese can be variables , class , object , functions , lists , dictionaries etc. There are certain rules defined for naming i. e. , Identifiers. I. An identifier is a long sequence of characters and numbers. II. No special character except underscore ( _ ) can be used as an identifier. III. Keyword should not be used as an identifier name. IV. Python is case sensitive. So using case is significant. V. First character of an identifier can be character, underscore ( _ ) but not digit. © Prognoz Technologies Pvt. Ltd. Version 1. 0

 © Prognoz Technologies Pvt. Ltd. Version 1. 0

© Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Literals: Literals can be defined as a data

Tokens & Comments(Cont. . ) Python Literals: Literals can be defined as a data that is given in a variable or constant. Python support the following literals: I. String Literals- can be formed by enclosing a text in the quotes. We can use both single as well as double quotes for a String. Eg: “Prognoz" , ’Prognoz’ Types of Strings: a). Single line String- Strings that are terminated within a single line are known as Single line Strings. Eg: >>> text 1='hello' © Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Literals(cont): b). Multi line String- A piece of

Tokens & Comments(Cont. . ) Python Literals(cont): b). Multi line String- A piece of text that is spread along multiple lines is known as Multiple line String. There are two ways to create Multiline Strings: 1). Adding black slash at the end of each line. Eg: >>> text 1='hello user' >>> text 1 'hellouser‘ 2). Using triple quotation marks: Eg: >>> str 2='''''welcome to SSSIT''' >>> print str 2 welcome to SSSIT © Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Literals(cont): III. Boolean literals: A Boolean literal can

Tokens & Comments(Cont. . ) Python Literals(cont): III. Boolean literals: A Boolean literal can have any of the two values: True or False. IV. Special literals. Python contains one special literal i. e. , None is used to specify to that field that is not created. It is also used for end of lists in Python. Eg: >>> val 1=10 >>> val 2=None >>> val 1 10 >>> val 2 >>> print val 2 None >>> © Prognoz Technologies Pvt. Ltd. Version 1. 0

 © Prognoz Technologies Pvt. Ltd. Version 1. 0

© Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Literals(cont): V. Literal Collections such as tuples, lists

Tokens & Comments(Cont. . ) Python Literals(cont): V. Literal Collections such as tuples, lists and Dictionary are used in Python. List: List contain items of different data types. Lists are mutable i. e. , modifiable. The values stored in List are separated by commas(, ) and enclosed within a square brackets([]). We can store different type of data in a List. Value stored in a List can be retrieved using the slice operator([] and [: ]). The plus sign (+) is the list concatenation and asterisk(*) is the repetition operator. Eg: >>> list=['aman', 678, 20. 4, 'saurav'] >>> list 1=[456, 'rahul'] >>> list ['aman', 678, 20. 4, 'saurav'] >>> list[1: 3] [678, 20. 4] © Prognoz Technologies Pvt. Ltd. >>> list+list 1 ['aman', 678, 20. 4, 'saurav', 456, 'r ahul'] >>> list 1*2 [456, 'rahul', 456, 'rahul'] Version 1. 0

Tokens & Comments(Cont. . ) Python Operators ØOperators are particular symbols which operate on

Tokens & Comments(Cont. . ) Python Operators ØOperators are particular symbols which operate on some values and produce an output. The values are known as Operands. Eg: 4 + 5 = 9 Here 4 and 5 are Operands and (+) , (=) signs are the operators. They produce the output 9. Python supports the following operators: Arithmetic Operators. Relational Operators. Assignment Operators. Logical Operators. Membership Operators. Identity Operators. Bitwise Operators. © Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Operators Arithmetic Operators: Operators Description // Perform Floor

Tokens & Comments(Cont. . ) Python Operators Arithmetic Operators: Operators Description // Perform Floor division(gives integer value after division) + To perform addition - To perform subtraction * To perform multiplication / To perform division % To return remainder division(Modulus) ** Perform power) © Prognoz Technologies Pvt. Ltd. Version 1. 0 exponent(raise after to

Tokens & Comments(Cont. . ) Python Operators Relational Operators: Operators Description < Less than

Tokens & Comments(Cont. . ) Python Operators Relational Operators: Operators Description < Less than > Greater than <= Less than or equal to >= Greater than or equal to == Equal to != Not equal to <> Not equal to(similar to !=) © Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Operators Assignment Operators: Operators Description = Assignment /=

Tokens & Comments(Cont. . ) Python Operators Assignment Operators: Operators Description = Assignment /= Divide and Assign += Add and assign -= Subtract and Assign *= Multiply and assign %= Modulus and assign **= Exponent and assign //= Floor division and assign © Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Operators Logical Operators: Operators Description and Logical AND(When

Tokens & Comments(Cont. . ) Python Operators Logical Operators: Operators Description and Logical AND(When both conditions are true output will be true) or Logical OR (If any one condition is true output will be true) not Logical NOT(Compliment the condition i. e. , reverse) © Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Operators Membership Operators: Operators Description in Returns true

Tokens & Comments(Cont. . ) Python Operators Membership Operators: Operators Description in Returns true if a variable is in sequence of another variable, else false. not in Returns true if a variable is not in sequence of another variable, else false. © Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Operators Identity Operators: Operators Description is Returns true

Tokens & Comments(Cont. . ) Python Operators Identity Operators: Operators Description is Returns true if identity of two operands are same, else false is not Returns true if identity of two operands are not same, else false. © Prognoz Technologies Pvt. Ltd. Version 1. 0

 © Prognoz Technologies Pvt. Ltd. Version 1. 0

© Prognoz Technologies Pvt. Ltd. Version 1. 0

Tokens & Comments(Cont. . ) Python Comments Python supports two types of comments: 1)

Tokens & Comments(Cont. . ) Python Comments Python supports two types of comments: 1) Single lined comment: In case user wants to specify a single line comment, then comment must start with ‘#’ Eg: # This is single line comment. 2) Multi lined Comment: Multi lined comment can be given inside triple quotes. eg: ''''' This Is Multipline comment''' © Prognoz Technologies Pvt. Ltd. Version 1. 0

I. Write a program that gets 2 string variables and 2 integer variables from

I. Write a program that gets 2 string variables and 2 integer variables from the user, concatenates (joins them together with no spaces) and displays the strings, then multiplies the two numbers on a new line. II. Write a program that prints your full name and your birthday as separate strings. III. Write a program that shows the use of all 6 math functions. Note: To complete this exercises refer assignment 1 - Part 1 & 2 © Prognoz Technologies Pvt. Ltd. Version 1. 0