asdf
asdf program
asdf program
Kartei Details
Karten | 27 |
---|---|
Sprache | Deutsch |
Kategorie | Übrige |
Stufe | Universität |
Erstellt / Aktualisiert | 02.12.2014 / 03.12.2014 |
Weblink |
https://card2brain.ch/box/asdf11
|
Einbinden |
<iframe src="https://card2brain.ch/box/asdf11/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
Lernkarteien erstellen oder kopieren
Mit einem Upgrade kannst du unlimitiert Lernkarteien erstellen oder kopieren und viele Zusatzfunktionen mehr nutzen.
Melde dich an, um alle Karten zu sehen.
Comments in Python starts with _, and extend to the end of the physical line.
hash character #
Complex numbers are supported; imaginary numbers are written with a suffix of (1) or (2). Complex numbers with a nonzero real component are written as (3), or can be created with (4) function.
(1) j
(2) J
(3) (real + imagj)
(4) complex(real, imag)
Complex numbers are always represented as two floating point numbers, the real and imaginary part. To extract these parts from a complex number z use (1) and (2).
(1) z.real
(2) z.imag
In interactive mode, the last printed expression is assigned to the variable (1). This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculation.
(1) _
Strings literals can span multiple lines in several ways. Continuation lines can be used with (1) as the last character on the line indicating that the next line is a logical continuation of the line.
Or, strings can be surrounded (2) or (3). End of lines do not need to be escaped when using (2), (3), but they will be included in the string.
(1) a backslash
(2) in a pair of matching triple quotes: """
(3) '''
Strings can be concantenated (glued together) with (1), and repead with (2)
(1) the + operator
(2) *
word = 'Help' + 'A'
The line above could also have been written (1). This only works with two literals, not with arbitrary string expressions.
(1) word = 'Help' 'A'
Strings can be subscripted (indexed). The first character of a string has subscription (index) (1). Substrings can be specified with the slice notation: tow indices separated by (2)
(1) 0
(2) a colon
word = 'HelpA'
(1) word[4]
(2) word[0:2]
(3) word[2:4]
(4) word[:2]
(5) word[2:]
(1) 'A'
(2) 'He'
(3) 'lp'
(4) 'He'
(5) 'lpA'
word = 'HelpA'
(1) 'A'
(2) 'He'
(3) 'lp'
(4) 'lpA'
(1) word[4]
(2) word[0:2] or word[:2]
(3) word[2:4]
(4) word[2:] or word[2:5]
word = 'helpA'
(1) How can we replace the 'h' with a 'x'?
(2) How can we replace 'help' with 'Splat'
(use index!)
(1) 'x' + word[1:]
(2) 'Splat' + word[4]
s[:i] + s[:i] = ?
s
s[:i] + s[:i] = ?
s
word = 'HelpA'
(1) word[1:100]
(2) word[10:]
(3) word[2:1]
(1) 'elpA'
(2) ''
(3) ''
word = 'HelpA'
(1) word[-1]
(2) word[-2]
(3) word[-2:]
(4) word[:-2]
(1) 'A' The last character
(2) 'p' The last-but-one character
(3) 'pA' the last two characters
(4) 'Hel' Everything except the last two characters
Indices may be negativ numbers. For example:
word = 'HelpA'
(1) 'A'
(2) 'p'
(3) 'pA'
(4) 'Hel'
word = 'HelpA'
(1) word[-1]
(2) word[-2]
(3) word[-2:]
(4) word[:-2]
word = 'HelpA'
(1) word[-0]
-0 is really the same as 0, so it does not count from the right!
>>>word[-0]
'H'
The built in function (1) returns the length of a string.
(1) len()
a = ['spam', 'eggs', 100, 1234]
Add 23 to the 100.
a[2] = a[2] + 23
a = ['spam, 'eggs', 100, 1234]
(1) replace 'spam' and 'eggs' with 1 and 12
(2) remove 100 and 1234
(3) insert 'bletch', 'xyzzy' in the middle
(4) insert (a copy of) itself at the beginning
(5) Clear the list: replace all itmes with an empty list
(1) a[0:2] = [1, 12]
(2) a[2:5] = []
(3) a[1:1] = ['bletch', 'xyzzy']
(4) a[:0] = a
(5) a[:] = []
How can we get the length of a list?
a (list)
len (a)
How can the variables a and b simultaneously get two new values 0 and 1? (multiple assignment)
a, b = 0, 1
The (1) loop executes as long as the condition remains true.
In Python any (2) integer value is true; (3) is false.
The condition may also be a string or list value, in fact any sequence; anything with a (4) is true, (5) sequences are false.
(1) while
(2) non-zero
(3) zero
(4) non-zero length
(5) empty
(1) less than
(2) greater than
(3) equal to
(4) less than or equal to
(5) greater than or equal to
(6) not equal to
(1) <
(2) >
(3) ==
(4) <=
(5) >=
(6) !=
The (1) statement writes the value of the expression(s) it is given.
(1) print
>>> i = 256*256
>>> print 'The value of i is', i
(Output?)
The value of i is 65536
(without quotes, and a space is inserted between items)
print: How to avoit the newline after the output?
A trailing comma avoids the newline after the output:
print b,
-
- 1 / 27
-