Printing
Print on the same line
print('One', end=' ')print('Two', end=' ')
print('Three')
==> One Two Three
>>> print('One', 'Two', 'Three', sep='*') One*Two*Three
>>>
concatenation
print('Enter the amount of ' + \'sales for each day and ' + \
'press Enter.')
string comparing
if name1 == name2:print('The names are the same.')
else:
print('The names are NOT the same.')
Functions
Functions (value returning)
def function_name():
statement
statement
etc.
return expression
- Value can be string or number
- value can be boolean: True or False
- value can be
Arguments by value
The form of argument passing that is used in Python, where a function cannot change thevalue of an argument that was passed to it, is commonly called pass by value. This is a way
that one function can communicate with another function. The communication channel
works in only one direction, however. The calling function can communicate with the called
function, but the called function cannot use the argument to communicate with the calling
function
Geen opmerkingen:
Een reactie posten