String formatting in Python - Purdue
String formatting in Python
Lab 10 03/28/18
Formatting expressions
>>>`This is a %s string with a number : %d and a floating point: %f ' % (`example', 42, 3.14)
? % operator allows string concurrent substitutions within a string.
? Allows specification of justification, minimum width, precision etc.
Formatting expressions
s
String
c
Int or str
d
decimal
e
Floating point with exponent (lower case)
E
Floating point with exponent (upper case)
f
Floating point
g
e or f
>>>`%d | %f | %s ' % (25, 3.141592653589793116,'test') >>>'%-10d | %f | %s' % (25,3.141592653589793116,'test') >>> '%d | %10.5f | %s' % (25,3.141592653589793116,'test')
Working with Lists
? myList = [1,2,3,4,5] ? for x in myList:
print x
String.rstrip() List.append() List.reverse() String.center(10) #10 is the widthx
Working with Lists
for x in myList:
Do something with x print x
print done
String.rstrip() List.append() List.reverse() sl=[`*','**','***','****','*****'] Using these functions with * produce the shapes shown
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- python strings rxjs ggplot2 python data persistence
- python print formatting for chap8 rutgers university
- a guide to f string formatting in python
- python programming exercises 5
- python strings methods
- python fundamentals syllabus rooman
- introduction to the csd python api pyapi 001
- string formatting in python purdue
Related searches
- string formatting in java
- c string formatting width
- replace string in python array
- f string formatting python
- string formatting c
- python string built in methods
- python string formatting integer
- python string formatting 3
- string formatting python
- f string formatting python 3
- formatting in python 3
- python string not in list