Mastery 26 Creation and use of strings

In this mastery I will write about strings.What are strings? Strings are characters that are enclosing in quotes. As simple as this:

st1= “Hello World”

we can do many operations with strings beginig with print that maybe is the most use it.

we can know the lenght of our string using the len() statement like this:

1.-print len(st1)—> this will give us an 11, because the string has 11 characters including spaces

 Another operation with strings is performed by the index staement like this:

2.-print st1.index(“o”)—>this will give us a 4, because the letter tell us to where we will count, star of 0.

other is this one

3.- print st1[1:3]—>this will give us “el” starting countig from 0 and end in the position 2, like I say in the last post of range, that mean stop that will stop in (stop-1)

 

Another interesting functions are the following:

4.-print string1.upper()
5.-print string1.lower()

Which will print a new string with all letters converted to uppercase and lowercase respectively.

Also we can create a new string with other string but different, what I mean? just like this:

st1 = “Hello World”

print st1[:6] + “python”—–>this will give us “hello python”.

In this link you can found more operations and information about strings: http://www.tutorialspoint.com/python/python_strings.htm

 

CC BY 4.0 Mastery 26 Creation and use of strings by Efrain Duarte is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.