Day 3 Python Learning Content-annotations and simple input and output

Source: Internet
Author: User

Part 1:

Comments are represented in 3 ways:

msg = "I love Beijing Tian ' an door!"

Print (msg)

#print (msg) #可以用作单行注释表示

' Print (msg) ' single quotation mark or double quotation mark can be used to denote multiple lines of comment

"" "Print (msg)" "" single quotation mark or double quotation mark * can be used to denote multiple lines of comment

Part 2:

Input usage:

Name = input ("Your Name:")

Age = Input ("Your Age:")

Print (name, age)

Part 3:

The difference between int and STR:

Death_age = 80, where the type of death_age is int, or integer, which can be seen through print (type (death_age)),

And input comes in all the content is STR, that is, the string, age input in such as 60,60 is a string,

If you use Death_age-age, you will get an error, and the string and integer cannot be +--arithmetic.

The workaround is: years_left = Int (age)-death_age, with an int () to make the type of age from the string into an int integer,

Similarly, if you use STR (), you can turn the variable of the type of an integer into a string.

Part 4:

The difference between print (Death_age, death_age-int (age), name) and print (Death_age + str (death_age-int (age) + name):

Before and after the two show similar effect, but the former is actually 3 independent values, the latter is a 1 value

Part 5:

If initial use:

Example 1:

Age_of_principal = 56

guess_age = Int (input ("Please enter your guess Age:"))

if guess_age = = Age_of_principal:

Print ("correct!") Python in the use of indention indentation in place of the braces {} In other languages, to limit scope, if the use of spaces, it is necessary to use a space, if the Tab tab, you have to use a tab, even if the space seems to be the same distance;

notepad++ to set tab = 4 spaces, to ensure that not only the Windows and Linux, and so on not only display the same length of space, while using the TAB key does not cause the production of tabs, resulting in a blank format error.

Else

Print ("wrong!")

Example 2:

score = Int (input ("Your score:"))

If score > 90:

Print ("A")

Elif score > 80: All if conditions are executed, once a certain piece is satisfied, will not continue to go down, but directly end the IF statement, the rest of the if part will not be executed, such as if score>, Elif score >95, if score=91, then the first article will be executed, the second straight end does not look.

Print ("B")

Elif score > 70:

Print ("C")

Elif Score > 50:

Print ("D")

Else

Print ("Lose")

Day 3 Python Learning Content-annotations and simple input and output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.