美文网首页
Strings&console output

Strings&console output

作者: MEMO_123 | 来源:发表于2015-04-20 17:20 被阅读0次
  1. 字符串string储存:字母,数字,符号,需要用英文双引号** “___” **;
name = "luog11"
age = "23"
  1. 代码** '___' **中,后一个 ** ' ** 意味着代码的结束,其后面的不会被执行,使用 ** \ ** 修正;
'there's  a bike'改正为:
'there\'s a bike'
  1. 字符串counting:index——字符串string中字母计数是中** 0 **开始,比如yes中三个字母的index依次为0、1、2;
c = cats[0]
x = index[4]
  1. string method:

len(string)→输出string的长度;name = John; len(name) = 4;
lower()→把string中的大写转换为小写

②对象为一个变量——不加引号:name = "MEMO"; print name.lower()→meme;```
>**upper()**→把string中的**小写**转换为**大写**;
>**str()**→可以把**非字符串**转换为**字符串**
```str(2)→可以把**数字**2转换为**字符**2;```
**注**:len()和str()函数可以对**除了字符串之外的数据类型**起作用;
而lower()和upper()函数只对字符串起作用,因而其使用的时候前面加**dot**;
5. 字符串连接concatenation:
```print "string1 " + "string2 " + "string3 "...```
注意上述string1和string2...后面的空格;
6. 上述连接字符串的时候,对象必须都是string,如果不是,使用**str()**;
```print "I have_" + str(2) + "_eggs"```
7. 使用 % ...字符串:

name_1 = John
name_2 = Lily
print "my name is %s, not %s." % (name_1, name_2)

name = raw_input(what's your name?)
age = raw_input(how old are you?)
color = raw_input(what's your favorite color?)
print “ so your name is %s, your age is str(age), and your favorite color is %s" % (name, age, color)

------------------------------------------------------

###小节
1. string的三种输入方法:

'string1'
"string2"
str(string3)

2. string method

len(XXX)
XXX.upper()
XXX.lower()

3. 输出string

print "XXX"
print "XXX " + "XXXX " + ...

4. 字符串的高级输出方法

print "%s, %s, %s..." % (string1, string2, string3...)

















相关文章

  • Strings&console output

    字符串string储存:字母,数字,符号,需要用英文双引号** “___” **; 代码** '___' **中,...

  • 03.ES6数组对象展开(spread)

    数组对象展开 output: output 浅拷贝 output 转换可迭代对象为数组 output output...

  • bash的四则运算

    加 output: 13 减 output: 9 乘 output: 22 除 output: 5 取余 outp...

  • output

    不会发泄,不会大吵大叫,不会大哭大笑,也不想和别人交流,文字,变成了我唯一的输出工具。就让我把所有的不满都写下来吧...

  • output!

    今天是和SCUjob这个app说再见的一天 但是后天下午1.30又将迎来asp的问候 今天还是圣诞节,之前打算让夏...

  • Output

    我这人没什么文笔,也写不出来什么让人觉得很优美的句子。我就挺喜欢五月天那种表达的方式,用简单的文字表达你想要说的,...

  • LoG函数可视化的Matlab实现

    Matlab 上运行: Output: 或者: Output: 俭朴版: Output: 参考资料How to g...

  • Handle a possible exception in J

    Output: While Output: This is useful when "@Test(timeout ...

  • php缓存机制的一点理解

    Output Control The Output Control functions allow you to ...

  • fsl处理DTI数据流程

    1. IM_0025 output_bvals output_bvecs output_info.txt outp...

网友评论

      本文标题:Strings&console output

      本文链接:https://www.haomeiwen.com/subject/xdtyfttx.html