Introduction to Python 2018 Edition
By Mark Lassoff and Julius Hernandez
4/5
()
About this ebook
Few programming languages provide you with the flexibility and pure power of Python.
If you're becoming a professional developer, or are early in your development career, adding the Python skill set isn't just a resume embellishment-- It's an empowering language that will allow you to write procedural code in many types of environments and for many uses.
Python is commonly used for server side programming for complex web applications or as a middle tier language providing web services or a communication layer with larger ecommerce systems. That being said, it's also a great language for beginners. The clear syntax makes it very easy to learn, and the powerful libraries make all types of programming possible. There are libraries for everything from games and graphics to complex mathematics to network and embedded programming.
Watch, Learn and Do
Programming is not a spectator sport and if you want to learn Python well, this book contains everything you need.
You'll be able to study and modify the code provided on your own to cement each topic. Python code coding lab exercises will familiarize you not just with Python syntax, but how real problem-solving in Python is done.
Mark Lassoff
Mark Lassoff 's parents frequently claim that Mark was born to be a programmer. Starting, in the mid-eighties at age 11, Mark was hard at work on his Commodore 64 writing games in the BASIC language. After completing a computer science degree, Mark developed software for several well-known internet startups during the initial internet boom of the mid 1990’s. Eight years ago Mark parlayed a two decades of software development experience into his latest entrepreneurial venture, LearnToProgram Media. LearnToProgram Media publishes online courses that teach mobile, web, and game development. Over 1,000,000 people have learned programming from Mark through online classes he has either authored or published. In addition to publishing popular courses and books LearnToProgram Media operates an internet video network which produces several programs on software development. Previously Mark founded PowerPlant Marketing, which created marketing automation software for REALTORS™. After the sale of PowerPlant, Mark went on to found Internet Broadcasting Group which counted among it’s launch clients Nike, Blue Moon Brewing Company and Opubco. Mark lives in Connecticut and speaks worldwide on software development, entrepreneurship and online learning. He has spoken at TechWeek NY, TechWeek LA, ATD ICE, and SXSW, among other large conferences. In his spare time he he enjoys aviation, mentoring new business owners and spending time with life-long friends and family.
Related to Introduction to Python 2018 Edition
Related ebooks
Python Programming Illustrated For Beginners & Intermediates: “Learn By Doing” Approach-Step By Step Ultimate Guide To Mastering Python: The Future Is Here!: The Future Is Here! Rating: 4 out of 5 stars4/5Python: Beginner's Guide to Programming Code with Python: Python Computer Programming, #1 Rating: 0 out of 5 stars0 ratingsPython Rating: 0 out of 5 stars0 ratingsPython Programming: Your Advanced Guide To Learn Python in 7 Days Rating: 0 out of 5 stars0 ratingsEssential Python 3 Rating: 0 out of 5 stars0 ratingsThe 1 Page Python Book Rating: 2 out of 5 stars2/5Python In - Depth: Use Python Programming Features, Techniques, and Modules to Solve Everyday Problems Rating: 0 out of 5 stars0 ratingsPython Apps on Visual Studio Code: Develop apps and utilize the true potential of Visual Studio Code (English Edition) Rating: 0 out of 5 stars0 ratingsPython: Advanced Guide to Programming Code with Python Rating: 0 out of 5 stars0 ratingsProgramming in C | Step by Step: The Simple Beginner's Guide Rating: 0 out of 5 stars0 ratingsAdvanced Python Development: Using Powerful Language Features in Real-World Applications Rating: 0 out of 5 stars0 ratingsPython for Developers: Learn to Develop Efficient Programs using Python Rating: 0 out of 5 stars0 ratingsPython: Programming For Intermediates: Learn The Basics Of Python In 7 Days! Rating: 0 out of 5 stars0 ratingsProgramming with Python Rating: 0 out of 5 stars0 ratingsPython Handbook For Beginners. A Hands-On Crash Course For Kids, Newbies and Everybody Else Rating: 0 out of 5 stars0 ratingsPython Programming: Your Beginner Guide To Learn Python in 7 Days Rating: 4 out of 5 stars4/5Python, PyGame, and Raspberry Pi Game Development Rating: 0 out of 5 stars0 ratingsPython All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsPython: Tips and Tricks to Programming Code with Python Rating: 0 out of 5 stars0 ratingsProfound Python Rating: 5 out of 5 stars5/5Python: Programming for Advanced: Learn the Fundamentals of Python in 7 Days Rating: 3 out of 5 stars3/5Python Programming Rating: 0 out of 5 stars0 ratings
Programming For You
Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsCoding All-in-One For Dummies Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Beginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5C Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Problem Solving in C and Python: Programming Exercises and Solutions, Part 1 Rating: 5 out of 5 stars5/5Code like a Pro in C# Rating: 0 out of 5 stars0 ratingsSpies, Lies, and Algorithms: The History and Future of American Intelligence Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5C All-in-One Desk Reference For Dummies Rating: 5 out of 5 stars5/5
Reviews for Introduction to Python 2018 Edition
4 ratings1 review
- Rating: 3 out of 5 stars3/5There are several errors in the book (mostly syntax/spacing/case errors), which can cause confusion. It also seemed that he gave the later subjects short shrift and was hurrying through it a bit. It's still worth a read for the starting out or starting over programmer.
Book preview
Introduction to Python 2018 Edition - Mark Lassoff
Chapter 1 – Introduction
Figure 1.1. The familiar Python logo. Python is a well-supported, open-sourced language. It is freely-available for both personal and commercial use.
Welcome to Python for Beginners! With this book, you will learn the basics of Python, a powerful high-level and object-oriented programming language that is suitable for both beginners and experienced programmers. The goal of Python is to make programming easy to learn. It is open-source and is free to use and distribute, even commercially.
Intended Audience
Prior knowledge of Python is not required to learn from this book. Whether you are new to programming or you are someone who has programmed before using another language, you will find this book to be the ideal resource for learning Python.
For beginners who are new to Python, computer science knowledge would be helpful. However, it is not required. It is important to spend time understanding the concepts and doing the coding exercises. This is a sure-fire way to retain knowledge gained from this book.
The concepts discussed in the book will be familiar to someone with prior programming experience. For those readers, it is expected that the book will fast-track their understanding of Python programming concepts and how they differ from the language/s they have used before.
At the end of the course, you will have the basic skills necessary to take your Python programming skills to the next level. Learn to Program’s Python for Game Development courses are perfect for that.
Figure 1.2. Learning the basics of Python programming has never been easier with the Python for Beginners video course on Learn to Program TV and this companion book. After you have completed this beginner’s course, you can take your Python development skills to the next level with our Game Development for Python courses.
What Does the Book Cover?
This book has 12 chapters, including this introductory chapter. We will go through the next chapters briefly below.
Figure 1.3. The home page of the Python.org website, where you can download installers and documentation on the Python programming language. The website also features the latest news and events about Python, and the robust Python user community.
In Chapter 2, you will start by downloading and installing Python (installation packages are available for Windows, Linux and other Unix-based platforms, and Mac OS X). You will then code your first Python program using IDLE, or the Integrated Development and Learning Environment, which is installed with Python. Your very first Python program would be a simple program. However, what better way is there to fire up the excitement of learning a programming language than writing your first program? You will then execute the program from the command line. In this chapter, you will also learn how to use the Python shell window interactively. You will be able to write and run programming commands directly from the shell window. You will then have a coding exercise at the end, that will reinforce the concepts discussed in the chapter.
Figure 1.4. Python includes a cross-platform IDE known as IDLE, for Integrated Development and Learning Environment. IDLE was coded entirely in Python and can be configured to your liking.
In Chapter 3, you will learn how the first program you wrote in Chapter 1 works. This chapter will teach you how to output the results from your program onto the screen, by using the Print function. You will also learn about the proper usage of separators and newlines, which allow a finer grain of control on displaying output on the command line. At the end, you will tie this all together with a coding exercise on the Print function.
Figure 1.5. IDLE has built-in syntax highlighting, and code indentation, among other features, commonly found in commercial IDEs.
Chapter 4 discusses the use of variables in Python. You might remember variables from your algebra class, such as in the expression x + 10 = 15, what is the value of the variable x? Variables play an important role in Python, as well as other programming languages. You will learn how to assign variables, and then review the different types of variables you can use in your programs, including numbers, strings, and substrings and how to concatenate them. You will also learn about the different variables that you can use in lists, tuples, and dictionaries (we will discuss these data structures in greater detail in Chapter 10). Finally, you will tie together everything you learned about variables in another coding exercise.
Chapter 5 focuses on the use of operators, which are used to complete expressions made up of variables. For example, in the expression x + 10 = 15, the symbols + and = are operators (the + sign is a mathematical operator, denoting that the number 10 should be added to the variable x, while the = sign is an assignment operator, which means it assigns the number 15 to the expression x+10). The order in which these operators are evaluated works is the same way as in math – given an expression, you should solve it in the following order: parentheses, exponents, multiplication, division, addition, and subtraction. In addition to mathematical operators, you will also learn about comparison and logical operators. As the name implies, a comparison operator compares two variables or values, while a logical operator allows you to join expressions. A coding exercise will be given at the end to test your newly-acquired knowledge.
In Chapter 6, you will learn about code branching, or decision making, in Python. Given a condition, which path should your program take? Does it go this way, or that? You will learn about various conditional statements, ranging from simple If to nested If-Else statements, and how to implement them properly in your Python programs. You will also learn about Python’s ternary, or conditional, operator, which works differently than similar operators in other programming languages. You will also have an opportunity to again test your understanding of the skills you learned in the chapter with another coding exercise.
Chapter 7 is all about loops. They perform an operation repeatedly, until all its conditions are met. You will learn about Python’s implementation of different kinds of loops. While loops are the simplest. For loops are implemented differently in Python, compared to other programming languages. Nested loops are contained within another loop, while break and continue statements allow greater control over an operation. In this chapter’s coding exercise, you will be asked to code a program that will compute interest on an investment. Your output will result in the first useful program in the course.
Chapter 7 is the midpoint of the course. Chapter 8 discusses Python’s powerful math functions, which are a strong suit of the language. It is one of the reasons why data analysts prefer Python to other programming languages. You will learn about casting functions, more advanced math functions and randomization functions. Casting functions are used to convert one variable type to another, such as by using int(), you can convert a floating-point number to an integer. Python’s advanced math functions allow increasingly complex calculations to be performed, while the random functions allow random number generation. This is useful for programs where random numbers are required. The sheer number of functions in Python’s Math library makes it impossible to cover all of them in the book. However, you will learn the most essential and important functions and how they can be used. Chapter 8 is similar to other functions, since it ends with a coding exercise that will test your knowledge about Python math functions.
Chapter 9 teaches you about the functions that you can use for string manipulation and processing in your Python programs. Like its math functions, the Python String library is so large that it is impossible to discuss them all in an introductory book on Python programming (the material may be enough to fill a book or two of its own). You will, therefore, only learn a few string functions that are essential to make you a competent Python programmer. As you continue on your coding journey, you will discover the other string functions on your own. Another coding exercise awaits you at the end.
Chapter 10 discusses lists, tuples, and dictionaries. These are data structures that allow you to store more complex data for your programs. There are many functions available for manipulating data stored in these structures. First, you will learn how to create lists and tuples and access the values available in them, by using the various tuple functions. Lists are like tuples, except that, once created, you can still edit them. By contrast, you cannot edit a tuple once it is created. You will learn the same things with dictionaries, which are like lists, except that the objects contained in a dictionary are accessed via keys (you access objects in a list via their position within the list). You will then learn how to manipulate data within these data structures yourself through another coding exercise.
In Chapter 11, you will learn about some of the time and date functions available in Python. This includes how to access data in a Time tuple, advance to the Calendar object and then learn about the time and calendar functions. You will apply what you have learned via a coding exercise involving these functions.
Chapter 12 builds upon your knowledge of the various built-in Python functions by teaching you how to write your own custom functions. The information contained in this chapter will allow you to start taking your programming skills to the next level. You will learn how to define and call a simple function, required argument functions, keyword argument functions, as well as the default arguments available to your functions. You will also learn how to use return statements with your functions. This allows them to return a value when called. You will also learn how to consume existing Python modules. The last part of this chapter teaches you how to create your own custom Python module. You will have the opportunity to apply all this critical information in a coding exercise.
By this time, you will nearly be at the end of your coding journey using Python. In the previous chapters, you did all your programming on the Python shell. In Chapter 13, input and output (I/O, as it is called in programming) from outside the shell will be the focus. You will learn how to let your programs read input from the keyboard and external files. You will then write to an external file using your program. Your coding exercise will be on file I/O.
Chapter 14 will present other topics that are designed to prepare you for more advanced Python programming skills. You will learn how to handle exceptions, or run-time errors in your program. You will then learn about web