Download presentation
Presentation is loading. Please wait.
Published byPearl Brown Modified over 9 years ago
1
Strings See Chapter 2 u Review constants u Strings, concatenation and repetition 1
2
Constants u Programmers use all uppercase letters for symbolic constants –Examples: TAX_RATE and STANDARD_DEDUCTION u Constants receive values with an assignment statement = 2 TAX_RATE = 33.5 BOARD_SIZE = 64
3
String Literals u In Python, a string literal is a sequence of characters enclosed in single or double quotation marks '' and "" represent the empty string Use ''' and """ for multi-line paragraphs –The display formatting follows exactly your given format u For multi-line expressions, use a \ if formatting should be determined when displaying the string 3
4
String Literals, Examples 4 >>> "This very long sentence extends all the way to \ the next line." 'This very long sentence extends all the way to the next line.'
5
Escape Sequences u The newline character \n is called an escape sequence 5
6
String Concatenation You can join two or more strings to form a new string using the concatenation operator + The * operator allows you to build a string by repeating another string a given number of times 6
7
Required Readings u Fundamentals of Python Sections 2.3.2 - 2.3.5. 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.