1 / 75

Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka

This Edureka Python tutorial will help you in understanding the various fundamentals of Python programming with examples in detail. This Python tutorial helps you to learn following topics: <br>1. Introduction to Python <br>2. Who uses Python <br>3. Features of Python <br>4. Operators in Python <br>5. Datatypes in Python <br>6. Flow Control <br>7. Functions in Python <br>8. File Handling in Python

EdurekaIN
Download Presentation

Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EDUREKA PYTHON CERTIFICATION TRAINING What is Hadoop? www.edureka.co/python

  2. Agenda ➢ Python Introduction ➢ Who uses Python? ➢ Python Features ➢ Operators in Python ➢ Datatypes in Python ➢ Flow Control ➢ Functions in Python ➢ File Handling in Python www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  3. Python Introduction www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  4. Python Introduction ➢ Python is an interpreted, object-oriented, high-level programming language with dynamic semantics ➢ Python was created by Guido Rossum in 1989 and is very easy to learn Object Oriented Procedure Oriented High Level Language Easy to Learn www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  5. Who uses Python? www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  6. Who Uses Python? Dropbox storage service codes both its server and desktop client software primarily in Python. The Raspberry Pi single- board computer promotes Python as its educational language. The popular YouTube video sharing service is largely written in Python. Google makes extensive use of Python in its web search systems. C O M PA N I E S U S I N G P Y T H O N NASA, Los Alamos, Fermilab, JPL, and others use Python for scientific programming tasks. Netflix and Yelp have both documented the role of Python in their software infrastructures. BitTorrent peer-to-peer file sharing system began its life as a Python program. The NSA uses Python for cryptography and intelligence analysis. www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  7. Python Features www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  8. Python Features Simple and Easy to Learn Python is a simple and easy to learn, read & write Free and Open Source Python is an example of a FLOSS (Free/Libre and Open Source Software) which means one can freely distribute copies of this software, read it's source code, modify it, etc. www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  9. Python Features High-level Language a=3 b=5 sum=a+b print(sum) 01001010110110 11101100001101 10110101100101 0101011010 compile One does not need to bother about the low-level details like memory allocation, etc. while writing Python script Portable Supported by many platforms like Linux, Windows, FreeBSD, Macintosh, Solaris, OS/2, Amiga, AROS, AS/400, BeOS, OS/390, PlayStation, Windows CE, etc. www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  10. Python Features Procedure Oriented Supports different Programming Paradigm Object Oriented Python supports procedure-oriented programming as well as object-oriented programming. C/C++ Extensible Python code can invoke C and C++ libraries, can be called from and C++ programs, can integrate with Java and .NET components www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  11. Zen of Python C/C++ www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  12. Installation Steps www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  13. Python Installation Go to www.python.org 1 Under Downloads tab, select the latest Python version for Windows 2 www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  14. Python Installation Open the installer and click on Run 3 www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  15. Python Installation Click on Install Now 5 Select ‘Add Python 3.6 to PATH’ 4 www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  16. Python Installation Start IDLE which is a Python GUI & start scripting 6 www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  17. Python Installation C/C++ IDLE stands for integrated Development and Learning Environment www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  18. Operators in Python www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  19. Operators in Python 1 Arithmetic Operators 2 Assignment Operators 3 Comparison Operators 4 Logical Operators 5 Bitwise Operators 6 Identity Operators 7 Special Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  20. Arithmetic Operators + >> 2 + 3 5 >> +2 1 Arithmetic Operators Add two operands or unary plus 2 Assignment Operators - >> 3 – 1 2 >> -2 3 Comparison Operators Subtract two operands or unary subtract 4 Logical Operators * >> 2 * 3 6 Multiply two operands 5 Bitwise Operators 6 Identity Operators / Divide left operand with the right and result is in float >> 6 / 3 2.0 7 Special Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  21. Arithmetic Operators 1 Arithmetic Operators ** >> 2 + 3 5 >> +2 Left operand raised to the power of right 2 Assignment Operators 3 Comparison Operators % >> 3 – 1 2 >> -2 Remainder of the division of left operand by the right 4 Logical Operators 5 Bitwise Operators // division that results into whole number adjusted to the left in the number line >> 2 * 3 6 6 Identity Operators 7 Special Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  22. Assignment Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  23. Assignment Operators >> x = 5 /= 1 Arithmetic Operators >> x/=5 >> print(x) 1.0 x = x / <right operand> 2 Assignment Operators %= >> x%=5 >> print(x) 0 3 Comparison Operators x = x % <right operand> 4 Logical Operators //= >> x //= 2 >> print(x) 2 x = x // <right operand> 5 Bitwise Operators 6 Identity Operators **= >> x**= 5 >> print(x) 32 x = x ** <right operand> 7 Special Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  24. Assignment Operators >> x = 5 &= 1 Arithmetic Operators >> x&=2 >> print(x) 0 x = x & <right operand> 2 Assignment Operators |= >> x|=2 >> print(x) >> 7 3 Comparison Operators x = x | <right operand> 4 Logical Operators ^= >> x ^= 2 >> print(x) 7 x = x ^ <right operand> 5 Bitwise Operators 6 Identity Operators >>= >> x >>= 2 >> print(x) 1 x = x >> <right operand> 7 Special Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  25. Comparison Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  26. Comparison Operators > 1 Arithmetic Operators >> 2 > 3 False True if left operand is greater than the right 2 Assignment Operators < 3 Comparison Operators >> 2 < 3 True True if left operand is less than the right 4 Logical Operators == >>2 == 2 True True if left operand is equal to right 5 Bitwise Operators 6 Identity Operators != >> x >>= 2 >>print(x) 1 True if left operand is not equal to the right 7 Special Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  27. Logical Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  28. Logical Operators 1 Arithmetic Operators and 2 Assignment Operators >> 2 and 3 3 Returns x if x is False , y otherwise 3 Comparison Operators or >> 2 or 3 2 Returns y if x is False, x otherwise 4 Logical Operators not 5 Bitwise Operators >> not 1 False Returns True if x is True, False otherwise 6 Identity Operators 7 Special Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  29. Bitwise Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  30. Bitwise Operators 1 Arithmetic Operators a | b 111 7 101 5 111 7 2 Assignment Operators Perform OR operation on each bit of the no. 3 Comparison Operators a & b 111 7 101 5 111 5 Perform AND operation on each bit of the number 4 Logical Operators 5 Bitwise Operators a ^ b 111 7 101 5 111 2 Perform XOR operation on each bit of the number 6 Identity Operators 7 Membership Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  31. Bitwise Operators 1 Arithmetic Operators 2 Assignment Operators a >> b 3 >> 2 = 0 0011 0000 Shift a right by b bits 3 Comparison Operators 4 Logical Operators a << b 3 << 2 = 12 0011 1100 Shift a left by b bits 5 Bitwise Operators 6 Identity Operators 7 Membership Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  32. Identity Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  33. Identity Operators 1 Arithmetic Operators 2 Assignment Operators is >> x = 5 >> x is 5 True True if the operands are identical (refer to the same object) 3 Comparison Operators 4 Logical Operators is not >> x = 5 >> x is not 5 False True if the operands are not identical (do not refer to the same object) 5 Bitwise Operators 6 Identity Operators 7 Membership Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  34. Membership Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  35. Membership Operators 1 Arithmetic Operators X = [1, 2, 3, 4, 5] 2 Assignment Operators is >> 3 in x True True if the operands are identical (refer to the same object) 3 Comparison Operators 4 Logical Operators is not True if the operands are not identical (do not refer to the same object) >> 3 not in x False 5 Bitwise Operators 6 Identity Operators 7 Membership Operators www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  36. Datatypes www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  37. Datatype ➢ No need to declare variables before using them ➢ Python is a loosely typed language. Therefore, no need to define the datatype of variables C/C++ Datatype Immutable Mutable Numbers Lists Strings Tuples Dictionaries Sets www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  38. Datatype Numbers Strings Immutable Tuples Lists Dictionaries Mutable Sets www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  39. Datatype ➢ Strings are sequences of one-character strings Example: sample = ‘Welcome to Python Tutorial’ Numbers Strings Immutable or sample = “Welcome to Python Tutorial” Tuples ➢ Multi-line strings can be denoted using triple quotes, ''' or ""“ Example: sample = “””Don’t Go Gentle into the good Night Rage! Rage, against the dying light””” Lists Dictionaries Mutable Sets www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  40. Datatype Sequence Operations: ➢ Concatenation: Numbers ‘Tutorial’ ‘Python’ ‘Edureka Tutorial’ Strings Immutable ➢ Repetition Tuples ** 2 ‘Edureka’ ‘EdurekaEdureka’ Lists ➢ Slicing Dictionaries string1[2:7] string1 = ‘Edureka’ Mutable ‘ureka’ ➢ Indexing Sets string1[-1] + string[1] string1 = ‘Edureka’ ‘da’ www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  41. Datatype Type Specific Method: ➢ find(): Numbers str.find ( ‘ureka’ ) str = ‘Edureka’ ‘ureka’ Strings Immutable ➢ replace() Tuples ‘Eureka’ str.replace ( ‘Ed’,’E’ ) str = ‘Edureka’ Lists ➢ split() [‘E’, ‘d’, ‘u’, ‘r’, ‘e’, ‘k’, ‘a’] Dictionaries s.split ( ‘,’ ) str = ‘E, d, u, r, e, k, a’ Mutable ➢ count() Sets str = ‘Edureka’ 2 str.count(‘e’, beg=2, end=6) www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  42. Datatype Type Specific Method: ➢ upper(): Numbers str.upper () str = ‘edureka’ ‘EDUREKA’ Strings Immutable ➢ max() Tuples ‘u’ max (str) str = ‘Edureka’ Lists ➢ min() str = ‘Edureka’ Dictionaries min ( str ) ‘a’ Mutable Sets ➢ isalpha() str = ‘Edureka’ str.isalpha() True www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  43. Datatype Numbers ➢ A tuple is a sequence of immutable Python objects like floating number, string literals, etc. ➢ The tuples can’t be changed unlike lists ➢ Tuples are defined using curve braces Strings Immutable Tuples Lists Dictionaries Mutable myTuple = ( ‘Edureka’ , 2.4, 5, ‘Python’ ) Sets www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  44. Datatype Sequence Operations: ➢ Concatenation: Numbers tup +( ‘d’ ) tup = ( ‘a’ , ‘b’ , ‘c’ ) ( ‘a’ , ‘b’ , ‘c’ , ‘d’ ) Strings Immutable ➢ Repetition Tuples (‘a’ , ‘b’ , ‘c’ , ‘a’ , ‘b’ , ‘c’ ) tup * 2 tup = ( ‘a’ , ‘b’ , ‘c’ ) Lists ➢ Slicing Dictionaries tup[1:2] tup = ( ‘a’ , ‘b’ , ‘c’ ) Mutable ( ‘b’ , ‘c’ ) ➢ Indexing Sets tup[0] tup = ( ‘a’ , ‘b’ , ‘c’ ) ‘a’ www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  45. Datatype Numbers ➢ A list is a sequence of mutable Python objects like floating number, string literals, etc. ➢ The lists can be modified ➢ Tuples are defined using square braces Strings Immutable Tuples Lists Dictionaries Mutable myList = [ ‘Edureka’ , 2.4, 5, ‘Python’ ] Sets www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  46. Datatype Sequence Operations: ➢ Concatenation: Numbers ‘d’ [ ‘1’ , ‘b’ , 2.5 ] [ 1 , ‘b’ , 2.5 , ‘d’ ] Strings Immutable ➢ Repetition Tuples ** 2 [ ‘a’ , ‘b’ , 2.5 ] [‘a’ , ‘b’ , ‘a’ , ‘b’ ] Lists ➢ Slicing Dictionaries list[1:3] list = [‘a’ , ‘b’ , ‘c’ ,’d’] Mutable ( ‘b’ , ‘c’, ‘d’ ) ➢ Indexing Sets ‘a’ list[0] list = [‘a’ , ‘b’ , ‘c’] www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  47. Datatype Type Specific Method ➢ append(value) Numbers List.append (‘d’ ) list = [1, ‘a’, 2.5] [ 1 , ‘a’ , 2.5 , ‘d’ ] Strings Immutable ➢ extend(list) Tuples list.extend ( [‘c’, ‘d’] ) list = [1, ‘a’, 2.5] [1 , ‘a’ , 2.5 , ‘c’, ‘d’] Lists ➢ insert(index, value) Dictionaries List.insert(2,’b’) list = [1, ‘a’, 2.5] Mutable [1, ’a’, ‘b’ , 2.5 ] ➢ pop() Sets [ ‘a’, ‘b’ ] List.pop() list = [‘a’ , ‘b’ , ‘c’] www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  48. Datatype Numbers ➢ Dictionaries are perhaps the most flexible built-in data type in Python ➢ Dictionaries, items are stored and fetched by key, instead of by positional offset Strings Immutable Tuples Value Lists Dictionaries Mutable myDict = { 1: ‘Josh’ , 2: ‘Bob’, 3: ‘James’ } Sets Key www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  49. Datatype Dictionary Examples ➢ empty dictionary Numbers myDict = {} Strings Immutable ➢ dictionary with integer keys Tuples myDict = {1: 'apple', 2: 'ball'} Lists ➢ dictionary with mixed keys Dictionaries Mutable myDict = {'name': 'John', 1: [2, 4, 3]} ➢ from sequence having each item as a pair Sets myDict = dict([(1,'apple'), (2,'ball')]) www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

  50. Datatype Dictionary Methods ➢ Accessing Dictionary Numbers myDict [1] myDict = {1: 'apple', 2: 'ball'} ‘apple’ Strings Immutable ➢ len() Tuples len(myDict) myDict = {1: 'apple', 2: 'ball'} 2 Lists ➢ key() myDict.key() Dictionaries [1, 2] myDict = {1: 'apple', 2: 'ball'} Mutable ➢ values() Sets myDict.values() [‘apple’, ‘ball’] myDict = {1: 'apple', 2: 'ball'} www.edureka.co/python EDUREKA PYTHON CERTIFICATION TRAINING

More Related