Вы находитесь на странице: 1из 2

#!

python3
# please print a keyword
# by Giorgi R.
import keyword
print ('There is ' + (str(len(keyword.kwlist))) + ' keywords in python')
print (keyword.kwlist)
#['False','None','True','and','as',
# 'assert','break','class','continue',
# 'def','del','elif','else','except',
# 'finally','for','from','global',
# 'if','import','in','is','lambda',
# 'nonlocal','not','or','pass',
# 'raise','return','try','while',
# 'with','yield']

def main():
while True:
keyword = input('Please print a keyword: ')
if keyword.lower() == 'false':
print('True and False are truth values in Python. They are the results
of comparison operations or logical (Boolean) operations in Python.')
elif keyword.lower() == 'none':
print('None is a special constant in Python that represents the absence
of a value or a null value.')
elif keyword.lower() == 'true':
print('True and False are truth values in Python. They are the results
of comparison operations or logical (Boolean) operations in Python.')
elif keyword.lower() == 'and':
print('and, or, not are the logical operators in Python. and will
result into True only if both the operands are True.')
elif keyword.lower() == 'as':
print('as is used to create an alias while importing a module. It means
giving a different name (user-defined) to a module while importing it.')
elif keyword.lower() == 'assert':
print('assert is used for debugging purposes.')
elif keyword.lower() == 'break':
print('break and continue are used inside for and while loops to alter
their normal behavior.')
elif keyword.lower() == 'class':
print('class is used to define a new user-defined class in Python.')
elif keyword.lower() == 'continue':
print('break and continue are used inside for and while loops to alter
their normal behavior.')
elif keyword.lower() == 'def':
print('def is used to define a user-defined function.')
elif keyword.lower() == 'del':
print('del is used to delete the reference to an object.')
elif keyword.lower() == 'elif':
print('if, else, elif are used for conditional branching or decision
making.')
elif keyword.lower() == 'else':
print('if, else, elif are used for conditional branching or decision
making.')
elif keyword.lower() == 'except':
print('except, raise, try are used with exceptions in Python.')
elif keyword.lower() == 'finally':
print('finally is used with tryexcept block to close up resources or
file streams.')
elif keyword.lower() == 'for':
print('for is used for looping. Generally we use for when we know the
number of times we want to loop.')
elif keyword.lower() == 'from':
print('import keyword is used to import modules into the current
namespace. fromimport is used to import specific attributes or functions into the
current namespace.')
elif keyword.lower() == 'global':
print('global is used to declare that a variable inside the function is
global (outside the function).')
elif keyword.lower() == 'if':
print('if, else, elif are used for conditional branching or decision
making.')
elif keyword.lower() == 'import':
print('import keyword is used to import modules into the current
namespace. fromimport is used to import specific attributes or functions into the
current namespace.')
elif keyword.lower() == 'in':
print('in is used to test if a sequence (list, tuple, string etc.)
contains a value.')
elif keyword.lower() == 'is':
print('is is used in Python for testing object identity.')
elif keyword.lower() == 'lambda':
print('lambda is used to create an anonymous function (function with no
name).')
elif keyword.lower() == 'nonlocal':
print('The use of nonlocal keyword is very much similar to the global
keyword. nonlocal is used to declare that a variable inside a nested function
(function inside a function) is not local to it, meaning it lies in the outer
inclosing function.')
elif keyword.lower() == 'not':
print('and, or, not are the logical operators in Python. and will
result into True only if both the operands are True.')
elif keyword.lower() == 'or':
print('and, or, not are the logical operators in Python. and will
result into True only if both the operands are True.')
elif keyword.lower() == 'pass':
print('pass is a null statement in Python. Nothing happens when it is
executed. It is used as a placeholder.')
elif keyword.lower() == 'raise':
print('except, raise, try are used with exceptions in Python.')
elif keyword.lower() == 'return':
print('return statement is used inside a function to exit it and return
a value.')
elif keyword.lower() == 'try':
print('except, raise, try are used with exceptions in Python.')
elif keyword.lower() == 'while':
print('while is used for looping in Python.')
elif keyword.lower() == 'with':
print('with statement is used to wrap the execution of a block of code
within methods defined by the context manager.')
elif keyword.lower() == 'yield':
print('yield is used inside a function like a return statement. But
yield returns a generator.')
else:
print('You did not enter a keyword!')

if __name__ == "__main__":
main()

Вам также может понравиться