Strings Chapter 6 Python for Everybody

Strings Chapter 6 Python for Everybody
1 / 1
Strings Chapter 6 Python for Everybody - slide 1 of 33 Strings Chapter 6 Python for Everybody - slide 2 of 33 Strings Chapter 6 Python for Everybody - slide 3 of 33 Strings Chapter 6 Python for Everybody - slide 4 of 33 Strings Chapter 6 Python for Everybody - slide 5 of 33 Strings Chapter 6 Python for Everybody - slide 6 of 33 Strings Chapter 6 Python for Everybody - slide 7 of 33 Strings Chapter 6 Python for Everybody - slide 8 of 33 Strings Chapter 6 Python for Everybody - slide 9 of 33 Strings Chapter 6 Python for Everybody - slide 10 of 33 Strings Chapter 6 Python for Everybody - slide 11 of 33 Strings Chapter 6 Python for Everybody - slide 12 of 33 Strings Chapter 6 Python for Everybody - slide 13 of 33 Strings Chapter 6 Python for Everybody - slide 14 of 33 Strings Chapter 6 Python for Everybody - slide 15 of 33 Strings Chapter 6 Python for Everybody - slide 16 of 33 Strings Chapter 6 Python for Everybody - slide 17 of 33 Strings Chapter 6 Python for Everybody - slide 18 of 33 Strings Chapter 6 Python for Everybody - slide 19 of 33 Strings Chapter 6 Python for Everybody - slide 20 of 33 Strings Chapter 6 Python for Everybody - slide 21 of 33 Strings Chapter 6 Python for Everybody - slide 22 of 33 Strings Chapter 6 Python for Everybody - slide 23 of 33 Strings Chapter 6 Python for Everybody - slide 24 of 33 Strings Chapter 6 Python for Everybody - slide 25 of 33 Strings Chapter 6 Python for Everybody - slide 26 of 33 Strings Chapter 6 Python for Everybody - slide 27 of 33 Strings Chapter 6 Python for Everybody - slide 28 of 33 Strings Chapter 6 Python for Everybody - slide 29 of 33 Strings Chapter 6 Python for Everybody - slide 30 of 33 Strings Chapter 6 Python for Everybody - slide 31 of 33 Strings Chapter 6 Python for Everybody - slide 32 of 33 Strings Chapter 6 Python for Everybody - slide 33 of 33
Strings Chapter 6 Python for Everybody www.py4e.com String Data Type A string is a sequence of characters A string literal uses quotes Hello or Hello For strings, means concatenate When a string contains numbers, it is still a

Related Topics

Download this presentation From Below

"Strings Chapter 6 Python for Everybody" is the property of its rightful owner. Permission is granted to download and print the materials on this website for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Presentation Transcript

01
Strings Chapter 6 Python for Everybody
www.py4e.com<br>
02
String Data Type A string is a sequence of characters
A string literal uses quotes 'Hello' or "Hello"
For strings, + means “concatenate”
When a string contains numbers, it is still a string
We can convert numbers in a string into a number using int() >>> str1 = "Hello"
>>> str2 = 'there'
>>> bob = str1 + str2
>>> print(bob)
Hellothere
>>> str3 = '123'
>>> str3 = str3 + 1
Traceback (most recent call last): File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
>>> x = int(str3) + 1
>>> print(x)
124
>>><br>
03
Reading and Converting We prefer to read data in using strings and then parse and convert the data as we need
This gives us more control over error situations and/or bad user input
Input numbers must be converted from strings >>> name = input('Enter:')
Enter:Chuck
>>> print(name)
Chuck
>>> apple = input('Enter:')
Enter:100
>>> x = apple – 10
Traceback (most recent call last): File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'int'
>>> x = int(apple) – 10
>>> print(x)
90<br>