![]() ![]() Starting with a simple example ensures we have the basics in place first, before moving on. This is a bit of a departure from our function’s existing functionality, but bear with us, as we are going to build up to something more complex (and useful) in a bit. Specifically, let’s return either True or False depending on whether the word supplied as an argument contains any vowels. Let’s start with a straightforward example of returning a single value from our search4vowels function. This behavior mimics how return works in the majority of other programming languages. When the interpreter encounters a return statement in your function’s suite, two things happen: the function terminates at the return statement, and any value provided to the return statement is passed back to your calling code. To support returning a value (or values) from a function, Python provides the return statement. That said, and above all else, your usage should be consistent.Īs well as using a function to abstract some code and give it a name, programmers typically want functions to return some calculated value, which the code that called the function can then work with. Which character you use to enclose your strings is up to you, although using the single quote character is very popular with the majority of Python programmers. Strings enclosed by a single quote character ( ') or a double quote character ( ") cannot span multiple lines: you must terminate the string with a matching quote character on the same line (as Python uses the end of the line as a statement terminator). Docstrings have an interesting characteristic in that they can span multiple lines (other programming languages use the name “heredoc” for the same concept). Even though you can use """ or ''' to surround your docstrings, most Python programmers prefer to use """. In Python, strings can be enclosed in a single quote character ( '), a double quote character ( "), or what’s known as triple quotes ( """ or ''').Īs mentioned earlier, triple quotes around strings are known as docstrings, because they are mainly used to document a function’s purpose (as shown above). ![]() Understanding the string quote characters ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |