General Flashcards
Printing documentation strings
> > > print(math.tanh.__doc__)
Returns the document string that is triple quotes “”” “””
Converting integers and strings to floats
> > > float(3)
3.0
Str(n) function
Converts any number to a string
> > > str(85)
‘85’
Int(x) function
Chops off extra digits
Round(x)
Rounds the number according to usual rules
Assignment statement
Left hand side, assignment operator, right hand side
Define new variable names, make point to values
Initialization statement, creates a new variable and assigns a value to it
Var = value
Y = ‘cat’
Multiple assignments
> > > x, y, z = 1, ‘two’, 3.0
> > > x
1
Etc
symbol
Comment or source code comment
Python ignores
Input function
Reads strings from the keyboard
If want numbers, then have to use subsequent int() or float() functions
How to capitalize?
X.capitalize()
How do you remove any unwanted white space characters?
Use strip() function
> > > ’ oven ‘.strip()
‘Oven’
What is stdout?
Standard output
Refers to the window where the text goes when printed, typically a simple text window.
What is stdin?
Standard input
Location from where the input function reads strings.
What is stderr?
Standard error
Refers to where the error messages are displayed.
What is the standard built in function for printing strings to the screen?
Print( )
> > > Print (‘Jack’, ‘ate’)
Jack ate
Or
»> print(‘jack’, ‘ate’, sep = ‘.’)
Jack.ate
Beeline character. \n