March 2020
Beginner to intermediate
342 pages
8h 38m
English
In most programming languages, you cannot go far without defining and calling your own functions. In Python, you define a function with the def keyword:
| | def welcome(user): |
| | PASSWORD = "1234" |
| | message = "Hi, %s! Your new password is %s" % (user, PASSWORD) |
| | return message |
This function generates a password for a new user. (Admittedly, the default password isn’t the most secure—but hey, at least it’s popular.) Then it composes a welcome message, and returns the message to the caller.
Pythonically, you don’t need to delimit the function’s body with brackets—you just indent it. Also, being Python dynamically typed, you don’t need to specify the type of the user parameter, ...
Read now
Unlock full access