The relationship between ASCII, Unicode, and UTF-8
In computer memory, Unicode encoding is used uniformly, and is converted to UTF-8 encoding when it needs to be saved to the hard disk or when it needs to be transferred.
When Notepad is edited, the UTF-8 characters read from the file are converted to Unicode characters into memory, and when the edits are complete, the conversion of Unicode to UTF-8 is saved to the file:
When you browse the Web, the server converts dynamically generated Unicode content to UTF-8 and then to the browser:
-------------------------------------------------------------
String formatting:
Name=input (' Please enter your name: ')
Sex=input (' Please enter your gender: ')
Print (' Welcome to you: ' +name ') the first use of + sign connection is less recommended
Print (' Welcome you: ', ' name '), connect with the number
Print (' str1 is ', str1, ' str2 is ', str2)
Print (' Welcome to%s '%name) use% placeholder this way generally
Print (' Welcome you%s, your sex is%s '% (name,sex)) Use placeholder% connection
(a) Placeholder:
%d for the following variable is an integer
%f is followed by a floating-point decimal%.2f to keep a few decimals rounded
The%s represents a string followed by
(b) If the parameters are small, using placeholders is simpler if the parameters are many . Format () is relatively simple
Age=int (Input (' Please enter your Age: '))
Grade=float (Input (' Please enter your score: '))
print (' your age {Yourage},e your score is {Yourgrade} '. Format (yourage=age,yourgrade=grade))
In parentheses (Qianmian=shuru) equals the field that is defined when the preceding field is its own placeholder, followed by the input variable name.
. format cannot be used with placeholders? Not sure
How many bits can be saved using. Format is not rounded
Age=int (Input (' Enter your score: '))
Grade=float (Input (' Enter your score: '))
Print (' Your score Age is:%s '%age)
Print (' Your score is:%f '%grade)
Print (' Your age is:%s, your score is:%.2f '% (Age,grade))
Print (' Your age is {You_age}, your score is {You_grade} '. Format (You_age=age,you_grade=grade))
#总结, Fomat does not care about the type of data, but%s needs to focus on different data types, using different characters such as%s%0.2f%d, etc.
# When the data is many, use the format data less can be used directly%s
----------------------------------------------------------------
String manipulation
A string can be evaluated by subscript, but because the string is an immutable variable, it cannot be modified by subscript.
Username = ' Li '
USERNAME[0]
Print memory address
namess1=[' AAA ', ' BBB ']
namess2=[' AAA ', ' BBB ']
Print (ID (NAMESS1))
Print (ID (NAMESS2))
Print (Namess1 is namess2)
----------------------------------------------------------
All string methods, which do not modify the value of the original string, will produce (return) a new string
But the list can modify the value, so the list of methods generally do not return a value, will only be directly modified, resulting in print when you need to assign a value before printing something
the string method that must be
Import string
Print (string.ascii_letters+string.digits) #大小写字母 + digits
Find and Index
# Print (Name.find (' n ')) #查找字符串的索引 will return 1 if not found
# Print (Name.index (' n ')) #查找字符串的索引 will not be found directly error
List and string have the index method but the list does not have a Find method
format : Formatting Strings
Name22= ' Lzc '
Age22=22
Print (' {name},{age} '. Format (Name=name22, AGE=AGE22)) #格式化字符串
Print (' abA123 '. Isalnum ()) # Whether it contains numbers or letters
Print (' 122 '. IsDigit ()) # is the number
Print (Name.lower ()) # turns lowercase
Print (Name.upper ()) # becomes uppercase
Strnames = ' ABCEDF '
Join stitching an iterative object with the specified connector to return a string
a_list=[' Q ', ' d ', ' h ', ' a ']
Print (". Join" (a_list)
Print (' * * '. Join (a_list) specified connector
Results:
Qdha
# join is used to stitch an iterative object through a string (list, tuple, dictionary?). the join of each element can only be spliced with the type int of the string type is not spliced
Strip remove spaces on either side or specify characters
# print (' \nmysql \ n '). Strip ()) # Default to remove both spaces and line breaks
# print (' Mysqlm '. Strip (' M ')) #当你传入某个字符串的话, it will only remove the string you specified
# print (' \nmysql \ n '. Lstrip ()) #默认去掉左边的空格和换行 Important
# print (' \nmysql \ n '. Rstrip ()) #默认去掉右边的空格和换行 Important
Replace # replacement string
A= ' Hello World '
B=a.replace (' World ', ' python ')
Print (b)
Split splits a string with a space and returns a split list similar to join
name1 = ' zcl p y zyz '
# print (name1. Split())
# print (name1. Split(', '))
#切割字符串, return a list, separate the string according to the string you specified, and put it in a list
#如果你什么都不写的话, separated by a space, multiple spaces are counted as a
---------------------------------------------------------
The difference between join and split;
Name= ' Lzc,liushneg,liuyang '
Print (' Split: ', Name.split ())
name1=[' Yubo ', ' hahha ', ' hehhe ']
Print (', '). Join (NAME1))
The results are as follows:
Split: [' Lzc,liushneg,liuyang ']
Yubo,hahha,hehhe
Split is a cut string that returns a list string into the list
Join applies to the list into a string
--------------------------------------------------------------
Other operations:
# p = Str.maketrans (' ABCDEFG ', ' 1234567 ') #前面的字符串和后面的字符串做映射
# print (' CC AE GG '. Translate (p)) #输出按照上面maketrans做映射后的字符串
# #下面是反解
# new_p = Str.maketrans (' 1234567 ', ' ABCDEFG ')
# print (' CC AE GG '. Translate (new_p))
Print (' 1+2+3\n1+2+3+4 '. Splitlines ()) #按照换行符分割
The upper one can be implemented with print (' 1+2+3\n1+2+3+4 '. Split (' \ n ')) You try it, huh?
Print (' Abcdef '. Swapcase ()) #大小写反转
---------------------------------------------------------------
# 4 ways to format a string
# Print memory address
#打印指定下标的元素
# Print Data type
# query List
#查询字符串中的不存在的字符用两种方法
#查询字符串中的存在的字符用两种方法
#连接一个列表中字符 (not digital)
#拆分字符串中并返回列表
# Verify whether the string contains numbers or letters
#检验字符串中是否是数字
# turn the string into uppercase
#把字符串变成小写
#去掉两边的空格 Remove the left space and remove the space on the right.
Character to the right of the character #去掉两边指定的字符 Z left
# Replace String
# front and back fields make a map
# Split by line break
# case Reversal
# Print the third fifth character print all characters except the last one after printing the second one
String Practice Topics:
-------------------------------------------------------------------------
# x = "234567ASDsdfghj" #切片和索引
# x = "Hello" #显示字符串长度, note is starting from 1
# x = "Hello World ASDF" #返回长度为100的字符串, and padding on the left 0
# x = "Hello World ASDF" #小写变为大写
# x = "234567ASDsdfghj" #大写变为小写
# x = "234567sdfghj" #判断是否含有至少一个区分大小写的字符, and these are lowercase
# x = "Hello World" #返回标题化字符串
# x = "Hello World" #翻转字符串中的大小写
# x = "Hello World" #同时执行lstrip和rstrip, delete both sides
# x = "Hello World" #检测是否以xx开头或结尾
# x = "234567ASDSD\NFASDGHJASD" #以 \ n line delimited, returns a list containing the elements
# x = "234567ASDsdfASDghjASD" #以A分隔x and can be specified in number of times
# x = "234567ASDsdfASDghjASD" #替换字符串 and can be specified in number of times
# x = "234567ASDsdfghj" #以7为中间符, Split X
# x = "234567ASDZzsdfghj" #返回x中最大的字母 (lowercase)
# x = "121 234567ASDsdfghj" #截掉x左边的1
# x = "234567sdfghj" #左对齐 and fills the remaining quantity with * (20)
x = "*" #以x为分隔符重新生成y
# x = "Asdf112321 gh123j" #判断是否首字符为大写, other lowercase
# x = "" #判断是否只包含空格
# x = "234567f" #判断是否只包含 * Numeric characters *
# x = "234567" #判断是否全为数字
# x = "234567sdfghj" #判断是否全为十进制数字
# x = "234567sdfghj" #判断是否全为字母
# x = "234567sdfghj" #判断是否全为字母或数字
# x = "Hello World" #index同find, but not found, will return an exception!!!
# x = "Hello World" #find查找字符串并返回索引值
# x = "name:{2},age:{1},sex:{0}" #format格式化字符串
# x = "Hello World" #在指定范围内, number of times to return L
# x = "Hello World" #中间插入字符串, both sides/padding *
Http://www.cnblogs.com/LiChaoAI/p/6959607.html
Job 2:
String a = "Aasmr3idd4bgs7dlsf9eaf"
1. Please remove the number of a string and output it as a new string.
2. Count the occurrences of each letter that appears in a string (ignoring case, a and a are the same letter),
and output it into a dictionary. Example {' A ': 3, ' B ': 1}
3. Remove the letters that appear multiple times in a string, leaving only the first occurrence, case insensitive. Cases
' Aasmr3idd4bgs7dlsf9eaf ', after removal, output ' asmr3id4bg7lf9e '
4. Press the character in the a string to output from high to low to the list, if the number of times is the same, in alphabetical order.
http://blog.csdn.net/youyouheheda/article/details/51212305
Python Beginner--string