CS 3101-3 - Programming Languages: Python - Lecture 2 ...
Strings
Files and IO
Functions
CS 3101-3 - Programming Languages: Python
Lecture 2: Strings/IO/Functions
Daniel Bauer (bauer@cs.columbia.edu)
September 17 2014
Daniel Bauer
CS3101-3 Python - 02-Strings/Functions/IO
1/47
Strings
Contents
Strings Files and IO Functions
Files and IO
Functions
Daniel Bauer
CS3101-3 Python - 02-Strings/Functions/IO
2/47
Strings
Files and IO
Functions
else in loops
while and for loops, that contain a break statement can contain an optional else clause. The else block is executed after the loop finishes normally, but NOT when it is terminated by break.
for n in range(2, 10): for x in range(2, n): # check if x is a factor of n if n % x == 0: print(n, '=', x, '*', n /x) break else: # didn't find a factor for n print(n, 'is prime')
$python prime.py 2 is prime 3 is prime 4=2*2 5 is prime number 6=2*3 7 is prime 8=2*4 9=3*3
Daniel Bauer
CS3101-3 Python - 02-Strings/Functions/IO
3/47
Strings
Strings Files and IO Functions
Files and IO
Functions
Daniel Bauer
CS3101-3 Python - 02-Strings/Functions/IO
4/47
Strings
Files and IO
Functions
String literals (1)
String literals can be defined with single quotes or double quotes. Can use other type of quotes inside the string.
>>> str = 'Hello "World"'
Can use ''' or """ to delimit multi-line strings.
>>> s = """Hello "World"
""" >>> print(s) Hello "World"
Daniel Bauer
CS3101-3 Python - 02-Strings/Functions/IO
5/47
................
................
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 scientific lecture notes aspp2021 start
- cs 3101 3 programming languages python lecture 2
- python programming an introduction to computer science
- introduction to computers programming strings and
- python ascii builtin function examples
- cmsc 201 fall 2015 lab 10 caesar cipher
- chapter 12 — string encoding an i
- common python functions cs303e elements of computers a
Related searches
- programming languages and their uses
- top programming languages 2019
- scientific programming languages ranking
- computer programming languages pdf
- history of programming languages timeline
- history of programming languages book
- programming languages history pdf
- all programming languages pdf books
- programming languages trends
- programming languages trend 2020
- most used programming languages 2019
- top programming languages tiobe