Day2 (string, formatted output, operator, process control), day2 Operator

Source: Internet
Author: User

Day2 (string, formatted output, operator, process control), day2 Operator
I. String

In Python, all characters with quotation marks are considered as strings!

What are the differences between single quotes, double quotes, and multiple quotes?

There is no difference between single quotes and double quotes, but in some cases, single quotes and double quotes must be used together.

For example, msg = "My name is Small Nine, I'm 22 years old! '"

 

What is the function of multiple quotation marks?

The function of multiple quotation marks is that multiple quotation marks must be used for strings with multiple lines. Otherwise, an error is returned!

String concatenation

String concatenation

Name = "small nine"

Age = "22"

Name + age # adding is simple Splicing

You can also multiply

Name * 10 # multiplication means copying multiple times and then splicing them together

Note: String concatenation can only be a string on both sides, and cannot be concatenated with numbers or other types.

Ii. Formatting output

 

1 name = input ("name") 2 age = int (input ("age") # convert string type to numeric type 3 job = input ("job ") 4 hometown = input ("hometown") 5 6 7 inf = "8 -------- info of % s --------- 9 name: % s10 age: % f11 job: % s12 hometown: % s13 --------- end ---------------- 14 "" % (name, name, age, job, hometown) 15 # s = string # string 16 # d = digit # Number 17 # f = float # Floating Point 18 print (inf)

Note that % s is generally used for the formatted output, because s does not report an error. If it is of another type, an error will be returned.

Iii. Operators

There are many types of computation that a computer can perform, not just the addition, subtraction, multiplication, division, but can be classified into arithmetic, comparison, logic, and assignment operations,

Member operations, identity operations, which are listed below: arithmetic operations, comparison operations, logical operations, and value assignment operations

 

 

 

Iv. Process Control

It can be divided into one branch, two branches, and multiple branches,

   1. Single Branch

If condition:

Code executed after the conditions are met

if num >= 90 and num <= 100  :    print("A")

  2. Dual Branch

If condition:

Code executed after the conditions are met

Else:

If the condition is not met, proceed with this section.

3. Multiple branches

If condition:

 

Code executed after the conditions are met

Elif condition:

If the preceding conditions are not met, click here.

Elif condition:

If the preceding conditions are not met, click here.

 

Else:

 

If the condition is not met, proceed with this section.

Match the score of the game, according to the score print level

 

    

Num = int (input ("Enter your score:") if num> = 90 and num <= 100: print ("A") elif num> = 80: print ("B") elif num> = 60: print ("C") elif num> = 40: print ("D") else: print ("E ")

 

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.