Python 3 - Tutorialspoint

2y ago
75 Views
21 Downloads
2.85 MB
512 Pages
Last View : 12d ago
Last Download : 3m ago
Upload by : Grant Gall
Transcription

Python 3About the TutorialPython is a general-purpose interpreted, interactive, object-oriented, and high-levelprogramming language. It was created by Guido van Rossum during 1985 – 1990. LikePerl, Python source code is also available under the GNU General Public License (GPL).Python is named after a TV Show called ‘Monty Python’s Flying Circus’ and not afterPython-the snake.Python 3.0 was released in 2008. Although this version is supposed to be backwardincompatibles, later on many of its important features have been backported to becompatible with the version 2.7. This tutorial gives enough understanding on Python 3version programming language. Please refer to this link for our Python 2 tutorial.AudienceThis tutorial is designed for software programmers who want to upgrade their Python skillsto Python 3. This tutorial can also be used to learn Python programming language fromscratch.PrerequisitesYou should have a basic understanding of Computer Programming terminologies. A basicunderstanding of any of the programming languages is a plus.Execute Python ProgramsFor most of the examples given in this tutorial you will find Try it option, so just make useof it and enjoy your learning.Try the following example using Try it option available at the top right corner of the belowsample code box #!/usr/bin/python3print ("Hello, Python!")Copyright & Disclaimer Copyright 2016 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of Tutorials Point (I)Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republishany contents or a part of contents of this e-book in any manner without written consentof the publisher.We strive to update the contents of our website and tutorials as timely and as precisely aspossible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of ourwebsite or its contents including this tutorial. If you discover any errors on our website orin this tutorial, please notify us at contact@tutorialspoint.comi

Python 3Table of ContentsAbout the Tutorial . iAudience . iPrerequisites . iExecute Python Programs . iCopyright & Disclaimer . iTable of Contents . iiPYTHON 3 – BASIC TUTORIAL . 11.Python 3 – What is New? . 2The future module . 2The print Function . 2Reading Input from Keyboard . 2Integer Division . 3Unicode Representation . 3xrange() Function Removed . 4raise exceprion . 4Arguments in Exceptions . 4next() Function and .next() Method . 42to3 Utility . 42.Python 3 – Overview . 6History of Python . 6Python Features . 73.Python 3 – Environment Setup. 8Local Environment Setup . 8Getting Python . 8Setting up PATH . 9Setting Path at Unix/Linux . 10Setting Path at Windows . 10Python Environment Variables . 10Running Python . 114.Python 3 – Basic Syntax . 13First Python Program . 13Python Identifiers . 14Reserved Words . 15Lines and Indentation . 15Multi-Line Statements . 17Quotation in Python . 17Comments in Python . 17Using Blank Lines . 18Waiting for the User . 18Multiple Statements on a Single Line . 18Multiple Statement Groups as Suites . 19Command Line Arguments . 19ii

Python 3Parsing Command-Line Arguments . 205.Python 3 – Variable Types . 23Assigning Values to Variables . 23Multiple Assignment . 23Standard Data Types. 24Python Numbers . 24Python Strings. 25Python Lists . 26Python Tuples . 27Python Dictionary . 27Data Type Conversion . 286.Python 3 – Basic Operators . 30Types of Operator . 30Python Arithmetic Operators . 30Python Comparison Operators . 32Python Assignment Operators . 33Python Bitwise Operators. 35Python Logical Operators . 37Python Membership Operators . 38Python Identity Operators . 39Python Operators Precedence . 407.Python 3 – Decision Making . 43IF Statement . 44IF.ELIF.ELSE Statements . 45Nested IF Statements . 48Single Statement Suites . 498.Python 3 – Loops. 51while Loop Statements . 52for Loop Statements . 56Nested loops . 59Loop Control Statements . 60break statement . 61continue Statement . 63pass Statement . 65Iterator and Generator . 669.Python 3 – Numbers . 68Mathematical Functions . 70Number abs() Method . 71Number ceil() Method . 71Number exp() Method . 72Number fabs() Method . 73Number floor() Method . 74Number log() Method. 75Number log10() Method . 76Number max() Method . 77Number min() Method . 78Number modf() Method . 79iii

Python 3Number pow() Method . 80Number round() Method . 80Number sqrt() Method . 81Random Number Functions . 82Number choice() Method . 82Number randrange() Method . 83Number random() Method . 84Number seed() Method . 85Number shuffle() Method . 86Number uniform() Method . 87Trigonometric Functions . 88Number acos() Method . 88Number asin() Method . 89Number atan() Method . 90Number atan2() Method . 91Number cos() Method . 92Number hypot() Method . 93Number sin() Method . 94Number tan() Method . 95Number degrees() Method . 96Number radians() Method . 97Mathematical Constants . 9810. Python 3 – Strings . 99Accessing Values in Strings . 99Updating Strings . 99Escape Characters . 100String Special Operators . 101String Formatting Operator . 102Triple Quotes . 104Unicode String . 105String capitalize() Method . 109String center() Method . 110String count() Method . 111String decode() Method . 112String encode() Method . 112String endswith() Method . 113String expandtabs() Method. 114String find() Method . 115String index() Method . 116String isalnum() Method . 117String isalpha() Method . 118String isdigit() Method . 118String islower() Method . 119String isnumeric() Method . 120String isspace() Method . 121String istitle() Method . 122String isupper() Method . 122String join() Method . 123String len() Method . 124String ljust() Method . 125String lower() Method . 125iv

Python 3String lstrip() Method . 126String maketrans() Method . 127String max() Method . 128String min() Method . 129String replace() Method . 129String rfind() Method. 130String rindex() Method . 131String rjust() Method . 132String rstrip() Method . 133String split() Method . 134String splitlines() Method . 135String startswith() Method . 135String strip() Method . 136String swapcase() Method . 137String title() Method . 138String translate() Method . 138String upper() Method . 140String zfill() Method . 140String isdecimal() Method . 14111. Python 3 – Lists . 143Python Lists . 143Accessing Values in Lists . 143Updating Lists . 144Delete List Elements . 144Basic List Operations . 144Indexing, Slicing and Matrixes . 145Built-in List Functions & Methods . 145List len() Method . 146List max() Method . 147List min() Method . 147List list() Method . 148List append() Method . 150List count() Method . 151List extend() Method . 151List index() Method . 152List insert() Method . 153List pop() Method . 154List remove() Method . 154List reverse() Method . 155List sort() Method .

Python 3 i About the Tutorial Python is a general-purpose interpreted, interacti

Related Documents:

Python Programming for the Absolute Beginner Second Edition. CONTENTS CHAPTER 1 GETTING STARTED: THE GAME OVER PROGRAM 1 Examining the Game Over Program 2 Introducing Python 3 Python Is Easy to Use 3 Python Is Powerful 3 Python Is Object Oriented 4 Python Is a "Glue" Language 4 Python Runs Everywhere 4 Python Has a Strong Community 4 Python Is Free and Open Source 5 Setting Up Python on .

Python 2 versus Python 3 - the great debate Installing Python Setting up the Python interpreter About virtualenv Your first virtual environment Your friend, the console How you can run a Python program Running Python scripts Running the Python interactive shell Running Python as a service Running Python as a GUI application How is Python code .

Python is readable 5 Python is complete—"batteries included" 6 Python is cross-platform 6 Python is free 6 1.3 What Python doesn't do as well 7 Python is not the fastest language 7 Python doesn't have the most libraries 8 Python doesn't check variable types at compile time 8 1.4 Why learn Python 3? 8 1.5 Summary 9

site "Python 2.x is legacy, Python 3.x is the present and future of the language". In addition, "Python 3 eliminates many quirks that can unnecessarily trip up beginning programmers". However, note that Python 2 is currently still rather widely used. Python 2 and 3 are about 90% similar. Hence if you learn Python 3, you will likely

There are currently two versions of Python in use; Python 2 and Python 3. Python 3 is not backward compatible with Python 2. A lot of the imported modules were only available in Python 2 for quite some time, leading to a slow adoption of Python 3. However, this not really an issue anymore. Support for Python 2 will end in 2020.

A Python Book A Python Book: Beginning Python, Advanced Python, and Python Exercises Author: Dave Kuhlman Contact: dkuhlman@davekuhlman.org

Mike Driscoll has been programming with Python for more than a decade. He has been writing about Python on his blog, The Mouse vs. The Python, for many years. Mike is the author of several Python books including Python 101, Python Interviews, and ReportLab: PDF Processing with Python. You can find Mike on Twitter or GitHub via his handle .

Launch Eclipse Install Python plug-in for Eclipse Add a Python Interpreter Create a Python Project Create a Python Program Run a Python Program Debug a Python Program 0 Introduction This tutorial is for students who want to develop Python projects using Eclipse. E