零基础入门学习Python(三):变量和字符串

  

  分享兴趣,传播快乐,

  增长见闻,留下美好!

  亲爱的您,这里是LearningYard新学苑。

  今天小编为大家带来的是

  零基础入门学习Python(三):

  变量和字符串

  Share interest,

  spread happiness,

  increase knowledge,

  and leave beautiful.

  Dear, this is the LearingYard Academy!

  Today, the editor brings the

  “Introduction to Python (III): Variables and Strings”.

  Welcome to visit!

  一、思维导图

  此推文关于零基础入门学习Python系列的内容主要如下:

  The main content of this tweet about the exercise series is as follows:

  

  本次推文通过语法知识和案例的结合来为大家讲解Python,但需要注意的是代码还是需要经常敲才能熟练。

  This tweet combines grammar knowledge and case studies to explain Python to everyone, but it should be noted that the code still requires frequent typing to become proficient.

  二、变量

  在Python中不会像C语言那样声明一个变量再赋值,而是直接给对象赋值。若需要在屏幕上打印,则需要用到print函数。

  示例:

  In Python, a variable is not declared and then assigned as in C language, but rather directly assigned to an object. If you need to print on the screen, you need to use the print function. Example:

  

  三、字符串

  (一)原始字符串

  通常反斜杠加上特定的字符会表示一个转义字符,所以当要打印这类原始字符串时需要在字符串前加r,此时转义字符无效。

  示例:

  (1) Original string

  Generally, the backslash plus a specific character will represent an Escape character. Therefore, when printing such original strings, you need to add r before the string, and the Escape character is invalid.

  Example:

  

  (二)长字符串

  当字符串变量过长,我们换行时可以再末尾加上反斜杠,这样表示续行。或者前面三个双引号,后面三个双引号(前后呼应,成双成对,即可以前面是单引号加双引号,也可以是其他的,但是后面必须与之对称)

  (2) Long String

  When the string variable is too long, we can add a backslash at the end of the line to indicate continuation. Or the first three double quotes, followed by the last three double quotes (echoing before and after, paired in pairs, meaning it can be preceded by a single quote followed by a double quote, or something else, but must be symmetrical after it)

  (三)字符串的加法和乘法

  520与‘520’不同

  字符串相加称为拼接,乘法为复制

  示例:

  (3) Addition and multiplication of strings

  520 is different from '520'

  Adding strings is called concatenation, while multiplication is called replication

  Example:

  

  

  今天的分享就到这里了。

  如果您对今天的文章有独特的想法,

  欢迎给我们留言,

  让我们相约明天,

  祝您今天过得开心快乐!

  That's all for today's sharing.

  If you have a unique idea about the article,

  please leave us a message, and let us meet tomorrow.

  I wish you a nice day!

  翻译:百度翻译

  参考:百度、哔哩哔哩

  声明:本文由LearningYard新学苑原创,若有侵权请联系删除

  文案&排版:易春秀

  审核:许江越