This course introduces the basics of Python 3, including conditional execution and iteration as control structures, and strings and lists as data structures. You'll program an on-screen Turtle to draw pretty pictures. You'll also learn to draw reference diagrams as a way to reason about program executions, which will help to build up your debugging skills. The course has no prerequisites. It will cover Chapters 1-9 of the textbook "Fundamentals of Python Programming," which is the accompanying text (optional and free) for this course.
The course is for you if you're a newcomer to Python programming, if you need a refresher on Python basics, or if you may have had some exposure to Python programming but want a more in-depth exposition and vocabulary for describing and reasoning about programs.
This is the first of five courses in the Python 3 Programming Specialization.

RD

Great course to learn the basics of Python. Loved the instructors and loved the detail-oriented lectures and learning material. Would highly recommend to anyone serious about learning Python.

PS

May 10, 2019

Filled StarFilled StarFilled StarFilled StarFilled Star

very nice explain of each and every topic in deeply nice textbook concepts with own e-notes its covered almost good content about basic python it is really good course for beginner in this :)

수업에서

General Introduction

In week one you will be introduced to programming in python through lectures and the Runestone textbook - an interactive online textbook built for this course. By the end of the module, you will have run your first python program, and learned how to draw images by writing a program.

강사:

Paul Resnick

Michael D. Cohen Collegiate Professor

Steve Oney

Assistant Professor

Jaclyn Cohen

Lecturer

스크립트

Welcome back. Sometimes it's necessary or convenient to be able to convert values from one type into another in Python, and for that, Python has type conversion functions. So, the type conversion functions that we'll learn right now will be int, to convert to an integer, float to convert to a floating point number and string str to convert to a string. Each of these type conversion functions, expects an argument and usually, we want to pass in an arguments that's another type. So, for example, if we're calling int to convert to an integer, then we'll usually pass in an argument that's something else, either a float or a string. So, let's look at that in code. So, here we print out the value 3.14 and then we print out the value of int when called with 3.14 as an input and the value of this overall expression is going to be 3.14 a float cast or converted into an integer. So, the value of that expression is going to be three. Now, when Python converts a float to a string, it always just does that by discarding or kind of cutting off the decimal point and everything after it. So, 3.14 becomes three. What that also means is that 3.99999 also becomes three. So, that's how Python chooses to cast a float to an integer. So, this will make sense sometimes if we do 3.0, but other times, it might end up being a little bit strange. So, casting negative 3.9999 from a float to an integer ends up being negative three. So, in addition to converting floats to integers, we can also convert strings to integers which actually comes in handy fairly often. So, here we have a string 2345, and let's say that we wanted to divide that string into the integer 2,345, we'd do that by calling the int function and using the string 2345 as input. Another note, if we take in something that's already an integer and call the int function on it, then we're going to get that same value back. So, if we call int 17, then we just get the integer 17 back. Now, we can call int on any string. So, for example, if we call int on this string, but Python isn't necessarily going to be able to convert every string into an integer. So, for example, here, this string starts out with 23, but it also contains bottles. So, when Python sees that we're trying to convert this string, which isn't quite an integer into an integer, then Python gives us int here. So, here we're told that on line eight, there's an invalid literal for int. So, it's telling us that this string can be converted into an integer. Now, the float function works just like the int function except rather than converting to an integer, it converts it to a float. So, if I call float on the string 123 period 45, then that converts it into a float 123.45 and if we print out the type of this expression float 12345, then we're going to get its type float. So, you can see that the value of this expression was the float 123.45 and the value of this expression which computed the type of this expression, is a float. Now, in addition to int in float, we can also convert int a string. So, for example, we might print out what's the value of the string 17 of string 123.45, and then if we print out what's the type of this expression, then we're going to get that this is a string. So, let's run our code to be sure that this is the case. So, we can see that when we print out strings 17, it prints out the string 17, it just so happens that the output actually matches up with if we printed out the integer, but this is a string, this is also a string because we converted it again using the str method, and then the type of this expression is a string. So, that's telling us that when we call str on this number, then we get a string back. So, one reason that we might want to use casting, is when we want to concatenate or combined values. So, let's suppose that we have an integer val, which is set to 55 and we want to print out the value is val, we get an error saying TypeError, that must be a string not an int, not an integer. So, we have to add a conversion to convert val from an integer to a string by calling the str function. So, we print out the value is, and then if this is an integer, we need to add the str to convert it to a string. What value is printed when the following statement executes? So, again, when we call the int function to convert or cast this float into an integer, Python does that by just cutting off everything that comes after the decimal place, and so even though this number rounds up to 54, we're going to instead get 53 as our answer. So, the answer here is B. That's all for now, until next time.