Difference between revisions of "Python quick reference"
From thelinuxwiki
(→variable operations) |
(→simple string assignment) |
||
Line 11: | Line 11: | ||
<source lang="python"> | <source lang="python"> | ||
>>> var1 = 'foo' | >>> var1 = 'foo' | ||
− | + | <source lang="python"> >>> </source>type(var1) | |
<type 'str'> | <type 'str'> | ||
>>> print var1 | >>> print var1 |
Revision as of 15:43, 14 August 2017
Contents |
Introduction
Lexical analysis
Data model
Execution model
Expressions
Simple statements
variable operations
assigenment examples
simple string assignment
>>> var1 = 'foo' <source lang="python"> >>>
<type 'str'> >>> print var1 foo
</source>
string assignment like above must be incapsulated by quotes or the right side is interpretted as a variable name.
example:
>>> var1 = foo Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 'foo' is not defined
print sing variable named foo
>>> print foo
print multiple variables with text
print 'my variable are %s %s' % (FOO, BAR)
Common string operations
print nth word of string
print s.split()[n]