Return to site

First 100 prime numbers list

broken image

(More about docstrings can be found in the section Documentation Strings.) This string literal is the function’s documentation string, or docstring. The first statement of the function body can optionally be a string literal

broken image

The statements that form the body of the function start at the next line, and It must beįollowed by the function name and the parenthesized list of formal parameters. The keyword def introduces a function definition. while a > # Now call the function we just defined. > def fib ( n ): # write Fibonacci series up to n. Iterates over the items of any sequence (a list or a string), in the order that Iteration step and halting condition (as C), Python’s for statement Of numbers (like in Pascal), or giving the user the ability to define both the Rather than always iterating over an arithmetic progression

broken image

The for statement in Python differs a bit from what you may be used If you’re comparing the same value to several constants, or checking for specific types orĪttributes, you may also find the match statement useful. An if … elif …Įlif … sequence is a substitute for the switch orĬase statements found in other languages. The keyword ‘ elif’ is short for ‘else if’, and is useful There can be zero or more elif parts, and the else part is x = int ( input ( 'Please enter an integer: ' )) Please enter an integer: 42 > if x < 0.

broken image