Skip to content

Commit 2e375fc

Browse files
author
kangxiaoyu
committed
python string execise20170420
1 parent 9dffe7b commit 2e375fc

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/env python
2+
# -*- coding:utf-8 -*-
3+
str = '张琰考上了研究生,好呀'
4+
print str
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/env python
2+
#-*- coding:utf-8 -*-
3+
print '%2d-%02d' % (3,1)
4+
print '%.2f' % 3.1415926
5+
print 'Age:%s. Gender:%s' % (25,True)
6+
#对于Unicode字符串,用法完全一样,但最好确保替换的字符串也是Unicade字符串。
7+
print u'Hi, %s' % u'Michael'
8+
#有时候,字符串里面的%是一个普通字符怎么办?这个时候就需要转义,用%%来表示一个%:
9+
print 'growth rate: %d %%' % 7
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/env python
2+
# -*- coding:utf-8 -*-
3+
4+
#测试中文问题。
5+
6+
#编写有格式的字符串。
7+
print 'Hi %s,your score is %d.' %('Bart',59)
8+
print 'Hello,%s' % 'world'
9+
print 'Hi, %s, you have $%d.' % ('Michael',1000000)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%d 整数
2+
%f 浮点数。
3+
%s 字符串
4+
%x 十六进制整数
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/env python
2+
# -*- coding:utf-8 -*-
3+
c = '康晓与'
4+
u = u'康小与'
5+
print c
6+
print u
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/env python
2+
str='I want to learn python'
3+
print str

0 commit comments

Comments
 (0)