Python input and output

Use the built-in print () function and Input () function to control input and output in Python

The usage of print () function is as follows:

print (output content) #The output content can be numbers, characters, and strings. But the string needs quotes

Such as:

a = 1 #variable a value is 1
b = 2 #variable b value is 2
print (5) #output number 5
print (a) #output a
print (b) #output b
print (a * b) #Output a * b
print("hello world") #输出hello world

By default, after a print () statement is output, it will automatically wrap. If you do n’t want to wrap, you can use a semi-comma to separate in a print ()

Such as:

print(a,b,'hello world')

At the same time, using print () can also output the content to a file

Such as:

fp = open (r'D: \ python \ mr.txt ',' a + ') #Open the file and create the file
print ("hello world", file = fp) #Output to file
fp.close () #Close the file

The usage of input () function is as follows:

variable = input ("Please enter:") #variable is the variable name, which can be changed

The numbers and characters entered in zaiPython3.x are input as strings, if you want to accept numeric values, you can convert

Such as:

num = (int)input()

 

Published 3 original articles · Likes0 · Visits15

Guess you like

Origin blog.csdn.net/qq_36595497/article/details/105488179