Python conditional statements and basic data types

Source: Internet
Author: User

First, if the use of several information

1. If basic statement

If 1==1:    print (' OK ')  #缩进四个字符, you can press the TAB key else:    print (' Error ')  
If 1 = = 1: Print ('    A1 ') print ('    A2 ') print (' End ')  

2.if nesting

if1 = = 1:    if2 = = 2:        Print('A1')        Print('A2')    Else:        Print('A3')Else:    Print('A4')

3.if elif

INP = input ('Please input INP:')ifINP = ='A1' :    Print('B1')elifINP = ='A2':    Print('B2')elifINP = ='A3':    Print('B3')Else:    Print('B4')

4. Use pass to represent the empty code, meaningless, only to represent the code block

if 1 = =1    :passelse        :print(' A1 ')
II. Basic data types

1. String (symmetric quotation marks, format not unique)

Addition:

n1="Alex"n2='nb'n3=n1+n2  Print(n3)

>> output is ALEXNB

Multiplication:

' Alex ' n2=n1*3print(n2)

>> output is Alexalexalex

2. Digital

Addition: +

Subtraction:-

Multiplication: *

Division:/

exponentiation: * *

Residual:% >> can be used to determine odd even

A = input ("' = a% 2if temp = = 0    :print (' C9>a is a evennumber ')else:    print (' A is a odd number ')

Business://

Python conditional statements and basic data types

Related Article

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.