Python3 basic input and output operations Case Study

This article introduces the basic input and output operations Python3 analyze the input and output Python3 basic syntax, encoding conversion, annotation and Chinese encoding related tips with examples in the form of a friend in need can refer to the
examples herein describes Python3 basic input and output operating. Share to you for your reference, as follows:

   数据的输入和输出操作是计算机最基本的操作,本节只研究基本的输入与输出,基本输入是指从键盘上输入数据的操作,基本输出是指屏幕上显示输出结果的操作。

2.1 Basic Input and Output

常用的输入与输出设备有很多,如摄像机、扫描仪、话筒、键盘等都是输入设备,然后经过计算机解码后在显示器或打印机等终端上输出显示。

2.2 to print () function output

---- The basic syntax:
print(输出内容) #其中输出内容可以是数字和字符串

print(10)
print("hello world!")

Shows the results
Here Insert Picture Description
under ** in Python, by default, a print () statement after the output will automatically wrap, if desired once output a plurality of contents and does not wrap, the content can be output using a comma in the English half-angle separately, as follows

 print(10, 20, "hahahaha")

Here Insert Picture Description
---- ASCⅡ code input can be used, but require () function to convert the ord with {chr () function can be converted into a digital code characters ASCⅡ]

print(chr(97))
print(chr(65))

Here Insert Picture Description
***** need to locate a particular symbol, the input method can be used to obtain the installation, if the input method is not installed, you can win + r charmap input code values to obtain other unicode
Here Insert Picture Description
2.3 using input () function Input

- Use input () may receive a user keyboard input.

tip = input("提示文字")
print(tip)

Display
Here Insert Picture Description
which tip to save input variable results, text within double quotes for prompt what to enter.

*** In Python3.x, whether digital or input characters will be read as a string, if wanted converted to a number, required received string type conversion, with int () function converts

tip = input("请输入一个数字")
num = int(tip)
print(num)

Here Insert Picture Description
2.4 Notes

---- 2.4.1 Single-line comments

The syntax is as follows:

# 注释内容

---- 2.4.2 multi-line comments: a pair of three quotes or a pair of three double quotes

'''
# 注释内容
tip = input("请输入一个数字")
num = int(tip)
print(num)
'''
  
"""
tip = input("请输入一个数字")
num = int(tip)
print(num)
"""

---- 2.4.3 Chinese comments (Python3 provide Chinese notation declaration syntax)

If you specify character encoding used type of Chinese encoding, need to add Chinese annotation statement at the beginning of the file, so you can specify the character encoding type of Chinese coded in the program, the code error will not occur.

Syntax:

# coding : 编码
# 或者
# coding = 编码

Specific examples are as follows

# _*_ coding : utf-8 _*_

We recommend the python learning sites to see how seniors are learning! From basic python script, reptiles, django, data mining, programming techniques, as well as to combat zero-based sorting data items, given to every love learning python small partner! Python veteran day have to explain the timing of technology, to share some of the ways to learn and need to pay attention to small details, click on Join us python learner gathering

Released six original articles · won praise 0 · Views 1306

Guess you like

Origin blog.csdn.net/haoxun06/article/details/104365644