1. Print () function

Output function

Prints the specified Chinese character to the screen

print("hello world")
Copy the code

The print() function can print multiple strings at once, separated by commas (,)

print("hello"."how"."are"."you")
Copy the code

Print () prints each string in turn, and when it encounters a comma “, “prints a space like this:

hello how are you
Copy the code

Print () can print an integer, or a calculated result

>>>print(300)
300
>>>print(100 + 200)
300
Copy the code

We can also make the printed results look prettier

>>>print("100 + 200 =".100 + 200)
100 + 200 = 300
Copy the code

Note: For the string “100 +200 =” it will be printed as is, but for 100+200, the Python interpreter automatically evaluates to 300, so it prints the above.

String addition, concatenating strings without generating Spaces

print("hello"."Hello")
Use ", "to connect
# Python Learning Exchange group: 531509025
print("he" + "llo")
Add strings, concatenate strings without generating Spaces

print(10+30)
# is not enclosed in quotes. It defaults to a numeric value, or a string if enclosed in quotes
If the value is joined with a plus sign, the default value is an expression that evaluates to the value

print("hello"+1) # complains
Different types of data cannot be joined using the plus sign
# Different types of data can be used ", "to make connections
print("1 2 3".2+3)
# enter
# input()
# Input with prompt message
# name = input(" Please enter your name ")
# print(name)
Copy the code

In Python, print is followed by a newline by default

To do this, add the end argument

n = 0
while n <= 100:
    print("n =",n,end=' ')
    if n == 20:
        break
    n += 1Output: n =0 n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 n = 10 n = 11 n = 12 n = 13 n = 14 n = 15 n = 16 n = 17 n = 18 n = 19 n = 20
Copy the code

Multiple values are compared

print('c'>'b'>'a')
print(5>1>2) output:True
False
Copy the code

2. Input () function

Input function

Python provides an input() function that lets the user enter a string and stores it in a variable, such as a user name

>>> name = input()
jean
Copy the code

How to view input:

>>> name
'jean'
Copy the code

Or use:

>>> print(name)
jean
Copy the code

Of course, sometimes with a friendly reminder, we can also do this:

>>> name = input("place enter your name")
place input your name jean
>>> print("hello,", name)
hello, jean
Copy the code