码迷,mamicode.com
首页 > 其他好文 > 详细

Strings

时间:2014-10-06 12:58:10      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:io   ar   for   strong   sp   div   art   c   on   

Strings

Another useful data type is the string. A string can contain letters, numbers, and symbols.

Strings need to be within quotes.

 

Escaping characters

backslash\

 

Access by Index

Each character in a string is assigned a number. This number is called the index

In Python, we start counting the index from zero instead of one.

‘MONTY‘[4]

 

String methods

Great work! Now that we know how to store strings, let‘s see how we can change them using string methods.

String methods let you perform specific tasks for strings.

We‘ll focus on four string methods: len(),lower(),upper(),str()

len(‘Ryan‘),‘Ryan‘.lower(),‘Ryan‘.upper(),str(3.14)

 

Dot Notation

Methods that use dot notation only work with strings.

On the other hand, len() and str() can work on other data types.

 

Printing Strings

The area where we‘ve been writing our code is called the editor.

The console (the window in the upper right) is where the results of your code is shown.

print simply displays your code in the console.

 

String Concatenation

 

 

Strings

标签:io   ar   for   strong   sp   div   art   c   on   

原文地址:http://www.cnblogs.com/southernduck/p/4008067.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!