The basics of the python learning process of Caiji (2)


Preface

Some basic statements and keywords about Python


1. The basic output statement of Python:

1. The basic output statement of Python:

print("好好学习")

The writing format is:

print("Sentence that needs to be output")

Note: The double quotation marks in parentheses must be double quotation marks in English.

2. "," connection and "+" connection:

In an output statement in Python, the "," and "+" signs can be used to connect the identifier and the output statement, such as:

","号:

s=1
print("Hello,Word",s,"你好")

The running result is:

Hello,Word 1 你好

"+"号:

print("1"+"1")

result:

11

the difference:

"," is to connect the output string and the identifier, and there will be a space between the string and the identifier when output.

The "+" sign is to connect the string and the string. It is not allowed to connect the string and the identifier value or the value, and there is no space at the connection of the output result.

Note: No matter the "," sign and "+" sign or other symbols, they must be in English.

2. Python's special output format:

1. Escape character:

\n: Newline

\a: bell

\b: backspace

\r: Enter

\f: change page

Here are just some of the more commonly used escape characters, let's briefly talk about them first.

2." end=" 和"sep=":

(1). "end=" can output the output result on the same line, or add a symbol at the end of the line, such as:

Same line:

print("z",end="")
print("1"+"1")

result:

z11

Add symbol:

print("z",end="*")

result:

z*

(2). "sep=" can be used to define the separator between output data, such as:

print("1","1","1","1",sep="*")

result:

1*1*1*1

Note: "end=" and "sep=" must use the "," symbol to connect to the preceding string. If there is connected data in front of "sep=", use "," to connect.

to sum up

(1). When making connections, be sure to pay attention to the data type and the difference between "," and "+".

(2). "end=" and "sep=" are two commonly used print parameters.

(3). The usage of escape characters is flexible and changeable. Some keywords in formatted output also belong to escape characters, and I will elaborate on them next.

Okay, finally let us shout again Python game

(The above comes from the understanding of a little novice, don’t spray if you don’t like it)

Guess you like

Origin blog.csdn.net/weixin_45279175/article/details/112471922