2.Strings and Console Output(字符串与输出)
生活随笔
收集整理的這篇文章主要介紹了
2.Strings and Console Output(字符串与输出)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、字符與字符串的賦值
brian = "Always look on the bright side of life!"caesar = "Graham" praline = "John" viking = "Teresa"
fifth_letter = "MONTY"[4]print fifth_letter# 輸出的是Y,從0開始計數
2、字符串的一些函數以及數值轉字符串
pi = 3.14 print str(pi)#數值轉字符串ministry = "The Ministry of Silly Walks"print len(ministry) # 長度 print ministry.upper() # 全部變成大寫 print ministry.lower() # 全部編程小寫
3、輸出補充
print "The value of pi is around " + str(3.14) print "Spam" + " and" + " eggs"string_1 = "Camelot" string_2 = "place"print "Let's not go to %s. 'Tis a silly %s." % (string_1, string_2)name = raw_input("What is your name?") quest = raw_input("What is your quest?") color = raw_input("What is your favorite color?")print "Ah, so your name is %s, your quest is %s, " \ "and your favorite color is %s." % (name, quest, color)
4、例子
from datetime import datetimenow = datetime.now()print str(now.year) + "/" + str(now.month) + "/" + str(now.day)+" "+ str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
轉載于:https://www.cnblogs.com/hzhrestart/p/3340460.html
總結
以上是生活随笔為你收集整理的2.Strings and Console Output(字符串与输出)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RHEL6基础之八查找、文件内容查看类命
- 下一篇: iptables 防火墙的基本使用