Learning and summary of print function

Learning and summary of print function 1

1. The difference between single quotes and double quotes

1. The same effect is that when printing text, letters and special symbols, you can use single quotes or double quotes to print.
(1) Single quote

print('哪吒')
$python main.py
哪吒

(2) Double quotes

print("哪吒")
python main.py
哪吒

2. Differences
Single quotation marks are used for English grammar, and double quotation marks are used for functional mechanism.
For example

print("Let's go to")
$python main.py
Let's go to
$

2. The difference between %x and %X

Both %0x and %x are output right-justified in hexadecimal format, and the output is an unsigned number.
When the width is not specified, the actual width of the data is output, and the system automatically eliminates the invalid 0 at the left end, so there is no difference in the display effect between %0x and %x.
In the case of specified width, in the specified output width range, when the actual data width is insufficient, use %0x for control and use 0 to fill in the front, and use %x for control to fill in with spaces in front of it. Such as:


```python

```cpp
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int main(void){
    
    
    int a=0x37;
    printf("%04X\n%4X\n",a,a);
    return 0;
}输出是:
0037
    37

If the actual data width is greater than the specified width, it will be output according to the actual width.

3.print and input functions

The function of print is output, and the function of input is input, which is to collect data. Such as

hobby = int(input('她喜欢1.逛街,2.旅游,3.美食。输入数字:'))6
if hobby ==1:
     print('拿我的卡,使劲花')
elif hobby==2:
     print('带你去浪漫的土耳其,还有东京和巴黎')
else:
     print('吃嘛嘛香')
python main.py
她喜欢1.逛街,2.旅游,3.美食。输入数字:6
吃嘛嘛香

The input function is summarized in four sentences:
terminal input must be assigned, the input value type is str, and the data type is converted at the source.

The print function is summarized as:
must be output, the output type has a string number calculation assignment character output.

That's it for today's sharing.
I hope that all friends will like to pay more attention. . . . .

Guess you like

Origin blog.csdn.net/qq_53283368/article/details/113996037