Python the second day

the perpetual day here make me confused about the time. I thought it was only 13 or 14 until saw the clock which showed it was 17 already.

Keep going python study

Screenshot from 2015-09-06 18:38:56

Screenshot from 2015-09-06 18:41:46

You write the name of the desired new type in the same way as a function call, for example

x = float("3.4")
print(x-1)

The input() function takes no arguments and always gives back a str.

By calling input() multiple times, you can access multiple lines of input. The first call to input() gets the first line, the second gets the second line, et cetera.

Screenshot from 2015-09-06 19:09:18

if没括号,后面有冒号,下一句要空格

  • Then, the body consisting of one or more indented lines. The number of spaces (the amount of indentation) doesn’t matter, but being inconsistent will cause an error since Python uses the amount of indentation to determine where you mean the body to start or stop.

Boolean expressions

print(2>1)
b = False
print(b)
print(type(b), type(2>1), type(True))
True
False
<class 'bool'> <class 'bool'> <class 'bool'>

Note that in Python, when you use the bool values True and False directly in a program, they must be capitalized or you will get an error.

 

Advertisements
Python the second day

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s