程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python learning (II. String)

編輯:Python

What I learned today is Python The content is a string :

Case code :

# character string :Python Single character type... Is not supported , A single character is also a string 
# String encoding :Python3 The default character is 16 position Unicode code 
# Use built-in functions ord() Can convert characters to corresponding Unicode code 
# Use built-in functions char() You can convert decimal numbers into corresponding characters 
# The result of printing is 65
print(ord('A'))
# The result of printing is 39640
print(ord(' high '))
# The result of printing is B
print(chr(66))
# Create string 
a = " test "
# Print test 
print(a)
# An empty string and len() function 
#Python Allow the existence of empty strings 
#len() Used to calculate how many characters a string contains 
# The result of printing is 2
print(len(a))
# Escape character 
# \( When at the tail ) Endurance 
# \\ Backslash notation 
# \' Single quotation marks 
# \“ Double quotes 
# \b Backspace 
# \n Line break 
# \t Horizontal tabs 
# \r enter 
a = "i\nam\n test "
# Print the results by :
# i
#am
# test 
print(a)
# String copy 
a = "sex"*4
# Print the results :sexsexsexsex
print(a)
# Print without wrapping call print Will automatically print a line break 
# Print without line breaks end
# Print the results :23123
print(23, end="")
print(123)
# The console gets the string 
# Input a Print a
myname = input(" Please enter your name :")
print(" Your name is :"+myname)
#str() Realize digital transformation string 
a = 123
print(str(a))
# Use [] Extract characters 
b = "123"
# The result is 2
print(b[1])
#replace() Implement string substitution 
# The string cannot be changed . however , We really need to replace characters , At this time , We can only do this by creating new strings 
# The result of printing is : 1 Shirley 3
print(b.replace('2', ' Shirley '))

That's all for my sharing ! Let's learn together !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved