Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Introduction to Python.pdf

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Prochain SlideShare
Fundamentals of python
Fundamentals of python
Chargement dans…3
×

Consultez-les par la suite

1 sur 55 Publicité

Plus De Contenu Connexe

Similaire à Introduction to Python.pdf (20)

Plus récents (20)

Publicité

Introduction to Python.pdf

  1. 1. Python
  2. 2. Scope and Application 02 Python real-world applications and their scope Installation 03 Understanding the process of installation of python Python Basics 04 Understanding the basics of python Python: Introduction and Different Versions 01 An introduction to python programming language, its versions, and their comparative study Agenda
  3. 3. Python: Introduction and Different Versions of Python
  4. 4. Python is a programming language that was created by Guido van Rossum It was first released in 1991 Features of python programming language Easy to learn, easy to code Object oriented elements Platform independent Interpreted Python: Introduction
  5. 5. There are two major versions of python, python 2.0, and python 3.0. • Python 2.0 was released in the year 2000. • Python 3.0 was released in the year 2008. • Python 3.0 is the latest major release of python, and we will be using this version to write codes. Python: Versions IMPORTANT! Python 3.0 is NOT completely backward-compatible with python 2.0.
  6. 6. Python: Versions Comparison Basis of comparison Python 3 Python 2 Release Date 2008 2000 Function print print ("hello") print "hello* Division of Integers Whenever two integers are divided, you get a float value When two integers are divided, you always provide integer value. Unicode In Python 3, default storing of strings is Unicode. To store Unicode string value, you require to define them with "u". Syntax The syntax is simpler and easily understandable. The syntax of Python 2 was comparatively difficult to understand. Rules of ordering Comparisons In this version. Rules of ordering comparisons have been simplified. Rules of ordering comparison are very complex. Iteration The new Range() function introduced to perform iterations. In Python 2, the xrange() is used for iterations.
  7. 7. Python is used for: Machine Learning Data Science Web Application Development Game Development Python: Applications Library Use pymongo Database connectivity TensorFlow Performing high-level computation Matplotlib Plotting numerical data Pandas Data analysis PyGame Develop games
  8. 8. • Machine learning is the study of computer algorithms that can improve automatically through experience and by the use of data. It is a part of artificial intelligence. • Machine Learning algorithms are fed with large amount of data and then these algorithms predict outcomes of the given problems using python. Machine Learning Algorithms in Python: • Linear regression • Decision tree • Logistic regression • Support Vector Machines (SVM) • Naive Bayes Python: Versions Python for machine learning
  9. 9. • Data science is an interdisciplinary field that uses scientific methods, processes, algorithms, and systems to extract knowledge and insights from noisy, structured, and unstructured data, and apply knowledge and actionable insights from data across a broad range of application domains. • Python is widely used for performing different data science operations on datasets like create, read, update, delete (CRUD), visualize, etc. Python: Versions Python for data science keras sklearn numpy matplotlib tensorflow
  10. 10. • Python offers many frameworks from which to choose from, including Bottle.py, Flask, CherryPy, Pyramid, Django and web2py. • These frameworks have been used to power some of the world's most popular sites such as Spotify, Mozilla, Reddit, etc. Python: Versions Python for web application
  11. 11. • Python provides a built-in library called pygame, which used to develop the game. • Pygame is a cross-platform library that is used to design video and browser games. • We can use the pygame library to make games with attractive graphics and suitable animation. Python: Versions Python for game development
  12. 12. Python: Installation
  13. 13. To download python, visit the following link: Python: Installation https://www.python.org/downloads/
  14. 14. Run the installer. 01 Make sure to select “Add Python to PATH” option on bottom left corner of the installer window. 02 In case this option was not selected, we have to add path to python installation in PATH variable manually. 03 Keep the default values for the remaining steps. 04 Python: Installation
  15. 15. • After installation is complete, to check the version of python installed on your system, use “python --version” command in cmd window. Python: Installation “python --version” command in cmd window
  16. 16. • To write and execute python code in cmd, use “py” Python: Installation
  17. 17. • An integrated development environment (IDE) is software for building applications that combines common developer tools into a single graphical user interface (GUI). • There are different types of IDEs like PyCharm, Visual Studio Code, etc. • These IDEs are popularly used to develop complex applications in different frameworks. • IDEs provide flexibility to use different programming languages like python, JavaScript, C++, etc. Python: Integrated Development Environment (IDE)
  18. 18. To download PyCharm, visit the following link and click on download button: Python: Pycharm IDE Installation https://www.jetbrains.com/pycharm/
  19. 19. Python: Pycharm IDE Installation Now, download community version installer by clicking download button below community.
  20. 20. Python: Pycharm IDE Installation Run the PyCharm installer. 01 Click next and you can change the destination folder by clicking the browse button. 02 Click on “create desktop icon” button and start installation by clicking the install button. 03 After installation, click the finish button. 04
  21. 21. • Visual Studio Code, also commonly referred as VS Code, is a source-code editor made by Microsoft for Windows, Linux, and macOS. • Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. Python: Visual Studio Code
  22. 22. To download vs code, visit the following link and click on download button: Python: Visual Studio Code Installation https://code.visualstudio.com/download
  23. 23. Python: Visual Studio Code Installation Run VScode installer. 01 You can change destination folder for installation of files. 02 Click “create desktop icon” button. 03 Also, make sure that you enable “add to path” and “Register code as an editor for supported files type” button. 04 Then click on next and install button. 05
  24. 24. Create a file in vs code with .py extension Go to extensions > search for “Python v2022.6.0” by Microsoft. Click install Python: Visual Studio Code Installation
  25. 25. Hands-on
  26. 26. Python: Basics
  27. 27. • Unlike other programming languages such as java, there is no need to write too much boilerplate code in python. • To print a string/message on the console window, print function is used. Our first python program: hello world! Python: Basics
  28. 28. • Write the code given in the image in a file. • Save it by the name “demo.py” • Files containing python source code are saved with .py extension Python: Basics Our first python program: hello world!
  29. 29. • To execute the code present in a file, use “py file-name.py” command in cmd window. Python: Basics Our first python program: hello world!
  30. 30. • Take a number input from user and then display that number in output. User input in python Python: Basics
  31. 31. • There is no keyword to declare variables in python. • Variables are created by writing the name and assigning the values. • A single variable can be used to store values of different types. Variable Python: Basics
  32. 32. • Take age input in years from user and then calculate this age in days by multiplying age by 365. • Find error in this code below. Python program for calculating age in days Python: Basics
  33. 33. Hands-on
  34. 34. • Some of the data-types present in python are: ▪ str ▪ int, float, complex ▪ bytes, ▪ bool ▪ list, set, tuple, range, dictionary Variables and data types Python: Basics Numeric Dictionary Boolean Set Sequence Type Integer Float Complex Number Strings Tuple List Python – Data Types
  35. 35. • To check the type of a variable in python, type() is used. Data types Python: Basics Code Output Important! String in python can be written using “ ” as well as ‘ ‘
  36. 36. Line by line execution and errors in python Python: Basics • In python, execution happens line by line meaning that the execution of the python program will happen from top to down. • Whatever line you have written at the top will be executed first and the rest of the lines will be executed sequentially. • If you do not follow the python language instructions or if you make a mistake while writing the code, then python will give you an error message in console.
  37. 37. Line by line execution and errors in python Python: Basics • An example to the errors and sequential programming is displayed below. • In this example “variable1” at line number 3, a variable is declared; it is access at line number 2, where an error is shown. • The error has occurred only at line number 2, but not in line 3 and 4, which get executed after this error. Execution was stopped at line number 2.
  38. 38. Hands-on
  39. 39. • Operators are used to perform operations on data, which is either received from user or manually entered. • The operators are divided into following groups: ▪ Arithmetic operators ▪ Assignment operators ▪ Comparison operators ▪ Logical operators ▪ Identity operators Membership operators most commonly used operators that we will discuss here are Arithmetic, Comparison, Assignment and Logical operators. Operators Python: Basics
  40. 40. Arithmetic operators Python: Basics 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
  41. 41. Arithmetic operators' hands on Python: Basics
  42. 42. Assignment operators Python: Basics Operator Example Example same as below = 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
  43. 43. Assignment operators' hands on Python: Basics
  44. 44. Comparison operators Python: Basics Operator Name Example == Equal x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y
  45. 45. Comparison operators’ hands on Python: Basics
  46. 46. Logical operators Python: Basics Operator Description Example and Returns True if both statements are true x < 5 and x < 10 or Returns True if one of the statements is true x < 5 or x < 4 not Reverse the result, returns False if the result is true not(x < 5 and x < 10)
  47. 47. Logical operators' hands on Python: Basics
  48. 48. Hands-on
  49. 49. Python is a programming language that was created by Guido van Rossum. It was first released in 1991. It is easy to learn and easy to code language. Unlike other programming languages such as java, there is no need to write too much boilerplate code in python. Use of famous code editors like Visual Studio code, PyCharm etc. Different operators in python include Arithmetic, Comparison, Assignment and Logical operators. Summary
  50. 50. Python: MCQs Q1. Main difference between python 2 and python 3 a) Print is a statement in python 2 and a function in python 3. b) Python 2 is syntactically difficult than python 3. c) Python 3 is not completely backward-compatible with python 2. d) Python 3 has more usage than python 2. e) None of the above Q2. Predict output of code given below a = 10 a = 20 a = 30 a = 40 print(a) a) 10 b) 20 c) 30 d) 40 e) None of the above
  51. 51. Python: MCQs Q3. Predict output of code given below a = 30 b = 40 print(a */ b) a) 1200 b) 0.75 c) Error message “invalid syntax” d) 40 e) None of the above Q4. Predict output of code given below a = True b = False print((a and b) or a) a) True b) False c) Error message “invalid syntax” d) None of the above
  52. 52. Python: MCQs Q5. Predict output of code given below a = 30 b = 40 c = 60 d = 100 print( (a <= 30 and b <=60) and (c == 60 or d <= 200)) a) True b) False c) Error message “invalid syntax” d) None of the above Q6. Predict output of code given below a = 20 b = 20 c = a*b print() a) 400 b) 20 c) Error message “print function empty” d) No output e) None of the above
  53. 53. Python: MCQs Q7. Predict output of code given below a = 30 b = 40 c = 60 d = 100 print( (a <= 30 and b <=60) or (c == 60 and d <= 200)) a) True b) False c) Error message “invalid syntax” d) None of the above Q8. Predict output of code given below a = 50 b = 60 c = 2000 d = 100 print( (a <= 30 or b <=60) or (c == 60 or d <= 200) ) a) True b) False c) Error message “invalid syntax” d) None of the above
  54. 54. Python: MCQs Q9. Predict output of code given below a = 2 a **= 3 b = 20 b /= 10 print(a**b) a) 20 b) 64.0 c) Error message “invalid syntax” d) None of the above Q10. Predict output of code given below a = 50 b = 100 c = 200 print((a < 1000 and b > 50) and c > 10) a) True b) False c) Error message “invalid syntax” d) None of the above
  55. 55. Thank You! Copyright © HeroX Private Limited, 2022. All rights reserved.

×