First Steps With Python Real Python.Welcome This tutorial details how to get started with Python.Its writteneditedupdated by Derrick Kearney Canadian, Python master, foodie and Michael Herman from the Real Python team, of course.I Derrick help administer several Python groups where I field countless questions each day.In this post Ill answer the question I hear the most, How do I get started with Python.What is Python Python, named after the British comedy group Monty Python, is an interpreted, interactive, object oriented programming language.Its flexibility allows it to do many things, both big and small.ReadingandW5.png' alt='Python Create Dictionary From List Of Variables Of 10' title='Python Create Dictionary From List Of Variables Of 10' />Python can be used to write simple programs, but it also possesses the full power required to create complex, large scale enterprise solutions.Some of the ways in which Python is used includes Desktop graphical application development, including games Mathematical and scientific analysis of data and,Web and internet development.Pythons presence in the world of computer programming can be found everywhere.For example, Python is used in some of the largest internet sites on earth like Reddit, Dropbox, and Youtube, to name a few.The popular Python web framework Django powers both Instagram and Pinterest.Lucas. Filmss award winning visual effects company, Industrial Light Magic, uses Python to make help make their magic come to life.Its easy to forget just how powerful Python is because its so easy to learn.Python Properties.Python isStrongly typed.It enforces data types so you cant concatenate a string and a integer, for example.Dynamically, implicitly typed.So, you dont have to explicitly declare variable data types.Data types are enforced at runtime.Case sensitive. For example, token and TOKEN are two different variables.Object oriented. Everything is an object.Getting Python a prelim.Python is free, open source software that works on Linux, Mac, Windows, and various other platforms 2.It comes preinstalled on Mac and most distributions of Linux however, you may need to download the latest version see below.To check your version, open the terminal and run the command python V.Choosing a Python Version.It can be confusing for both new and seasoned programmers on deciding between Python 2 or 3.Fortunately, there are few syntactical differences between the two and you can run both version on your computer.Currently, there are two main versions of Python 2.Only version 3. 5.Python 2. 7. x as well as 3.Which version is right for youWell, thats up to you.Honestly, there are few differences between the two that will affect you at this early stage, so either choice will suffice.Plus, once youve learned one, its not too difficult to learn the other.In general, if youre just starting to learn Python, go with 3.However, 2. 7x has much more support from third party libraries.If you know youll need to use a library that has not been ported to version 3.The examples in this series will be shown in version 3.That said, most of the examples will work fine with either version since many of the features and updates added to 3. Drivers Education Academy Marshfield Wi Map . Well discuss any differences that you should be aware of as they arise.How do I get Python Regardless of your operating system, you can download Python from the Python Software Foundation PSF.Lists. Lists, which are called Arrays in nearly every other programming language, group various types of data together.Create a print statement.Print is one of the basic functions of Python, and is used to display information in the terminal during a program.Glossary The default Python prompt of the interactive shell.Often seen for code examples which can be executed interactively in the interpreter.Grab the version specific to your OS and processor 3.OS specific instructions Mac I strongly recommend using Homebrew to install and manage different version of Python.Check out the directions here.You can also download Python from the PSF.Linux Again, Python is included on various flavors of Linux.Be sure to upgrade to the latest version using the package manager, if necessary.Windows Download Python direct from the PSF.Windows users Make sure you select the option to add Python to your system path during the installation process From the drop down select the option, Will be installed on local hard drive.Confirming the Python Install.Lets do a quick sanity check to ensure Python installed correctly.Python Shell. Open the Python Interactive Shell Mac Open your terminal and run python or python.Linux Open your terminal and run python.Windows If you have only one version of Python installed simply run python.If you have both Python 2.Python 3 installed, run python for Python 2.Python 3. Windows users Ensure that your account has administrative privileges Run the command prompt at an elevated level by right clicking the command prompt icon, and then selecting Run as Administrator.The interactive Python Shell should open, and your command prompt or terminal window should look similar to this 1.Python 3. 4. 1 v.May 1. 8 2. 01. 4, 0.GCC 4. 2. 1 Apple Inc.Type help, copyright, credits or licensefor more information.While youre here, you might as well run your first line of codePython 2 1 print Python is funPython 3 1 printPython is funIf youre running Python 2.Python 3. x. You should see And thats it Youve just written your first Python programEach time you entered a line, Python immediately executed the statement, displaying the value between the quotes.Once done, you can use exit to leave the Python Shell.Or Mac and Linux users Ctrl D plus Return.Windows users Ctrl Z plus Return.Keep your terminal or command prompt open.We still have more to do Lets continue using the Shell as we run through the Python primitives.Language Primitives.In this section well look at the Python primitives variables, built in data types, comments, syntax, and semantics.Variables. Variables are containers for data.The syntax to declare them is variablename variablevalue.While you can name variables anything youd like except for a few reserved keywords, you should use a naming scheme that makes intuitive sense.The variable name should provide some indication as to what the values assigned to it are.For example, many new programers, use simple variable names like x and y.Do err, try not to do this.Instead, if you have two numbers say 1 and 5.That way when others read your program, they can make an educated guess that num.Think of others when writing your programs, as well as your future self.Your future self will thank you.Built in Data Types.Python has a number of built in data types such as numbers integers, floats, complex numbers, strings, lists, tuples, and dictionaries.Each of these can be manipulated using Operators.Functions. Data type methods.Be sure to type each example out along with me.Numbers. Numbers can be integers, floating points, Booleans, or complex numbers.The former three are the most important Integers are whole numbers 1, 2, 2.Floats have decimal points 1.Booleans represent either True or False or 1 or 0.They represent data that can only be one thing or another.Manipulating numbers.Operators. Youve seen operators before.Theyre things like addition or concatenation and subtraction, just like you learned in Elementary school.Addition. 5. num.Subtraction. 3. 2 6 Multiplication.Division. 4. 0. 7 3 Modulus returns the remainder from division1.Raise to the power.Putting your pre algebra skills to the test, lets look at comparisons, which evaluate to boolean values e.True or False or 1 or 0.Functions. Python provides you with a number of built in functions for manipulating integers.These are always available to you.Please note These functions can be used on any data type.There are a number of modules available in the Python Standard Library as well, such as math.To use the functions associated with these modules, youll first have to import the module.More on this later.For now, lets look at a few examples of built in functions.This function does NOT round the input up ceiling to the nearest integer it simply throws out anything after the decimal point flooring and returns the number.So the input of 1.NOT 1. 1. Similarly, 3.Data type methods.Besides functions, there a number of data type methods associated with each type of number.True. 1. False. Strings.Strings are lines of text that are declared with single or double quotes 1.Manipulating strings.Operators. Like numbers, you can concatenate strings string concatenation 1.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |