4. Built-in Types

newpythonlogo4. Built-in Types
https://docs.python.org/3.4/library/stdtypes.html

s[i] = x item i of s is replaced by x

del s[i:j] same as s[i:j] = []

4.4. break and continue Statements
The break statement, like in C, breaks out of the smallest enclosing for or while loop.
https://docs.python.org/3.4/tutorial/controlflow.html

4.10. Mapping Types — dict

loop that searches for prime numbers
https://docs.python.org/2/tutorial/controlflow.html
http://www.programiz.com/python-programming/examples/prime-number-intervals

array.append(x)
https://docs.python.org/3.4/library/array.html

lista.append(“a”)
AttributeError: ‘str’ object has no attribute ‘append’

Built-in Functions
https://docs.python.org/3.4/library/functions.html
len()
sorted(iterable[, key][, rev erse]

Keywords
Escape sequence
https://docs.python.org/3.4/reference/lexical_analysis.html

str.find(sub[, start[, end]])
str.join(iterable)
str.lower()
str.partition(sep) -> tupla
str.split(sep=None, maxsplit=-1) -> list
https://docs.python.org/3.4/library/stdtypes.html

Text Processing Services
https://docs.python.org/3.4/library/text.html

6.3 The dir() Function
>>>dir(sys)

>>> import string

# cf dir(str)
# dir(”.join)
# print(”.join.__doc__)

>>>dir(string)
[… ‘ascii_letters‘, ‘ascii_lowercase’, ‘ascii_uppercase‘, ‘capwords’, ‘digits‘, ‘punctuation‘, ‘whitespace’]
related:
https://franzcalvo.wordpress.com/2015/12/06/dir-globals-locals-vars

# cf “Hola”[0].islower()
>>> “Hola”[0] in string.ascii_lowercase
False
>>> “Hola”[1] in string.ascii_lowercase
True

#cf print(chr(i), end=”)
>>> for i in range(ord(“a”), ord(“z”) + 1):
____print(chr(i))

>>>l = ”

>>> for i in range(ord(‘a’), ord(‘z’)+1):
____l += chr(i)

>>> l == string.ascii_lowercase
True

>>> counter = 0
>>> for i in string.punctuation:
print(“This is string.punctuation[“, counter, “]: “, i)
print(“”)
counter += 1

>>> counter = 0
>>> for i in string.whitespace:
print(“This is string.whitespace[“, counter, “]: “, i)
print(“”)
counter += 1

16.2. io — Core tools for working with streams
https://docs.python.org/3.4/library/io.html
readline()

file object
https://docs.python.org/3/glossary.html#term-file-object

>>> with open(‘spamspam.txt’, ‘w’, opener=opener) as f:
… print(‘This will be written to somedir/spamspam.txt’, file=f)

The Python Tutorial > 7. Input and Output > 7.2.1. Methods of File Objects¶
https://docs.python.org/3/tutorial/inputoutput.html
#f is a file object
for line in f:
… print(line, end=”)

====================

split()
http://www.dotnetperls.com/split-python

How do I iterate through the alphabet in Python?
http://stackoverflow.com/questions/228730/how-do-i-iterate-through-the-alphabet-in-python

Find all occurrences of a substring in Python
http://stackoverflow.com/questions/4664850/find-all-occurrences-of-a-substring-in-python
[m.start() for m in re.finditer(‘test’, ‘test test test test’)]

>>> help(str.find)
“we can build it ourselves!”

Sequences also support slicing: a[i:j]
https://docs.python.org/3/reference/datamodel.html

>>> “”.find(“a”)
-1

Beginner’s Guide to Python
https://wiki.python.org/moin/BeginnersGuide

Python for Beginners
https://www.python.org/about/gettingstarted

print(b, end=‘ ‘)
The end=' ' command will display the output on the same line …
http://www.wikihow.com/Start-Programming-in-Python

============================

to nest lists

operator: in, is
https://docs.python.org/3.5/library/operator.html

& | used with sets
http://stackoverflow.com/questions/6488928/where-are-the-ampersand-and-vertical-bar-characters-used-in-python

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s