前言:
今天大家对“python转义括号”可能比较注重,小伙伴们都需要剖析一些“python转义括号”的相关知识。那么小编在网上搜集了一些有关“python转义括号””的相关内容,希望你们能喜欢,各位老铁们一起来了解一下吧!
分享兴趣,传播快乐,增长见闻,留下美好!
亲爱的您,这里是LearningYard学苑。今天小编为大家带来“学习知多少(python篇):字符串”,欢迎您的访问。
Share interests, spread happiness, increase knowledge, and leave a good legacy!
Dear you, this is The LearningYard Academy. Today Xiaobian brings you "Learn how much to know (python):string”, welcome your visit.
一、概念
字符串是 Python 中最常用的数据类型。我们可以使用引号 ( ' 或 " ) 来创建字符串。创建字符串很简单,只要为变量分配一个值即可。例如:
var1 = 'hello word!'
var2 = "Hi!"
1、 the concept
Strings are the most commonly used data type in Python. We can use quotation marks ( ' or " ) to create strings. Creating a string is as simple as assigning a value to the variable. For example:
var1 = 'hello word!'
var2 = "Hi!"
二、Python 访问字符串中的值
Python 不支持单字符类型,单字符在 Python 中也是作为一个字符串使用。
Python 访问子字符串,可以使用方括号来截取字符串。
2、Python accesses the value in the string
Python does not support single-character types, and single-character is also used as a string in Python.
Python accesses substrings, which can be truncated using square brackets.
三、转义字符
在需要在字符中使用特殊字符时,python 用反斜杠 \ 转义字符。
3、Escape characters
Python escapes the character with the backslash when special characters are required.
四、案例
4. Cases
(1)编写程序,要求输入一个字符串,然后输入一个整数作为凯撒加密算法的密钥,然后输出该字符串加密后的结果。
凯撒加密算法原理:
把明文中每个英文字母替换为该字母在字母表中后面第k个字母,如果后面第k个字符超过字母表范围,则把字母表首尾相接,也就是字母Z的下一个字母是A,字母z的下一个字母是a。要求明文中的大写字母和小写字母分别进行处理,大写字母加密后仍为大写字母,小写字母加密后仍为小写字母。
(1) Write a program that requires input of a string, and then enters an integer as the key of the Caesar encryption algorithm, and then outputs the result of the string encryption.
How the Kaesar encryption algorithm works:
Replace each English letter in the plaintext with the kth letter after the alphabet, and if the kth character after it exceeds the range of the alphabet, the alphabet is followed from beginning to end, that is, the next letter of the letter Z is A, and the next letter of the letter z is a. Uppercase and lowercase letters in plaintext are required to be processed separately, and uppercase letters remain uppercase letters after encryption, and lowercase letters remain lowercase letters after encryption.
(2)编写程序,模拟打字练习程序的成绩评定。假设 origin 为原始内容,userInput 为用户练习时输入的内容,要求用户输入的内容长度不能大于原始内容的长度,如果对应位置的字符一致则认为正确,否则判定输入错误。最后成绩为:正确的字符数量/原始字符串长度,按百分制输出,要求保留 2 位小数。
(2) Write a program to simulate the grading of the typing practice program. Assuming that origin is the original content, userInput is the content entered by the user during practice, and the length of the content entered by the user cannot be greater than the length of the original content, and if the characters in the corresponding position are consistent, it is considered correct, otherwise the input is judged to be wrong. The final score is: correct number of characters/original string length, output on a percentage scale, 2 decimal places required.
今天的分享就到这里了。
如果您对今天的文章有独特的想法,
欢迎给我们留言,
让我们相约明天。
祝您今天过得开心快乐!
That's all for today's sharing.
If you have a unique idea for today’s article,
please leave us a message,
and let us meet tomorrow.
I wish you a happy day !
本文由learningyard新学苑原创,如有侵权,请联系我们!
翻译来源于谷歌翻译
部分来源于
百度文库
清华大学出版 董付国《Python程序设计基础》
编辑&排版|百味
审核|闫庆红
标签: #python转义括号