Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic input and output methods of python

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today Xiaobian to share with you the basic input and output methods of python what related knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you have some gains after reading this article, let's learn about it together.

Python basic input and output 1.input input function

input function: takes user input and stores it as a string.

>>> name = input("Please enter your name: ") Please enter your name: >? onceday>>>name'onceday'

Note that even the numbers you enter are saved as strings!

The input function returns the user input intact and wraps it into a string.

The input function can sometimes be cleverly used to block or pause programs

2. print output function

Used to format content for display on standard output, primarily referring to on-screen displays.

Print can accept multiple strings, variables of string type, or printable objects. Each string is separated by commas "," and connected into a string output. print prints each string in turn, and prints a space for each comma "," encountered.

print('aaa','bbb','ccc')aaa bbb ccc

For statements like print(a+"a"+b), you compute the value of a+"a"+b first, and then print it. print() automatically executes the internal statement and outputs the desired result.

print function prototype: print(self, *args, sep ='', end ='\n', file=None)

sep parameter: Separated symbol, default is a space;

end parameter: End method after printing, default is newline\n. If you set end ='', you can print continuously on one line without line breaks. Flexible print control can be achieved by using print parameters.

2.1 print output color control (terminal valid)

Sometimes we need to set different colors for useful information to achieve emphasis, highlight, and aesthetic effects. In the command line or linux terminal, colors are controlled by escape sequences that begin with ESC and are represented by\033 in code (ESC ASCII code is 27 in decimal, equal to 33 in octal,\0 in octal). Note: color control is only available in linux terminal interfaces.

Display mode: \033[display mode; foreground color; background color m text\033, such as\033[0m].

foreground background color 3040 black 3141 red 3242 green 3343 yellow 3444 blue 3545 magenta 3646 cyan 3747 white display mode meaning 0 terminal defaults 1 highlight 4 underline 5 flash 7 highlight 8 invisible print ('\033 [1;31m*' * 50, '\033[0 m')#highlight red, then restore terminal defaults

The above is "Python's basic input and output methods what" all the content of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report