Python basic data type annotation entry constant flow control user input

Getting Started with Python

First, the constant

In Python, unlike other languages there is absolutely constant, changes will be error, there is a convention provision in Python - Constant is the variable name in uppercase .

Try to maintain a quantity does not change, there is this constant actually doing it in my life there are some dead set amount such as birthdays, ID code and so we should also have some of these things, from the design of our do not let anyone beginning to change, so this thing is constant.

Second, comments

For some obscure code label or explanation.

Divided into two types: code notes will not be executed

  • Single-line comments (comment when the line)
    • #号在行首
  • Multi-line comments
    • """ """ ''' ''' 可以换行
Third, the basic data types
  • Integer

    • Integer integer numbers and then we learn the same, you can add or subtract, multiply and divide
  • String

    • String addition

      s1 = 'a' 
      s2 = 'bc'
      print(s1 + s2)
    • String multiplication

      name = '坚强'
      print(name*8)
  • Boolean

    bool is a Boolean value, a Boolean value total is divided into two states

    True is true

    False is false

Fourth, the user input
s = input('请输入你喜欢的东西')

input is fixed format, meaning the input, the content inside the parentheses is prompt, the user is prompted to look at the statement, user input so that input is received and then assigned to the string s

Fifth, process control
  • if

    age = input("输入年龄:")
    if int(age) >= 18:
        print("成年了,能干成年人的事了")
  • if else

age = input('请输入您的年龄:')
if int(age) > 18:
    print('你可以去网吧尽情的嗨皮了')
else:
    print('你现在还不行啊!')
  • if elif elif elif multiple choice or 1 0

    num = input('请输入要比较的数字:')
    if int(num) >= 22:
        print('可以扯证了')
    elif int(num) >= 18:
        print('成年了,可以干一些成年的事了')
    elif int(num) < 18:
        print('还是小屁孩')  
  • if elif elif else a multiple-choice

    num = input("请输入要比较的数字:")
    if num > 60:
        print("大了")
    elif num < 60:
        print("小了")
    else:
        print("猜对了")
  • Nested if if

    name = input('请输入名字:')
    if name == 'meet':
        age = input('请输入年龄:')
        if int(age) == 18:
            print('输入全部正确')
        else:
            print('年龄输入错误!')
    else:
        print('名字输入错误!')
  • if if if multiple choice

  • Parallel relationship of the individual to perform three if satisfied

Guess you like

Origin www.cnblogs.com/liuxianhui/p/11469534.html