Categories: Python

Keywords in Python programming language

Keywords in Python programming language

In this tutorial, we will discuss the Keywords in Python programming language

Keywords are the reserved words in python

Keywords are reserved words in python. We can not use a keyword as a variable name, function name or any other identifier language.

1. and – and is a logical operator in python. Only if “and” and “if” operands are true, the result will be true. Otherwise, if one operand becomes false, the result will be false. If both operands are false, the return would be false.

The truth table of and keyword

Example of usage of and keyword

2. as – as is used to when we want to give a module a different(user define) alias

3. assert – 

4. break – break keyword is used inside of whileloop and forloop

Example for break

5. class Python is an object-oriented programming language,

We can define our own class or user-defined class using the class keyword.

Defining a class in Python is simple. A python class can consist a lof collection of related properties or attributes and methods
Class can be defined anywhere in python. But it is a good practice to define a single class in a module.

Syntex of class in python

6. continue –  continue keyword is used  inside of whileloop and forloop

7. def – def is used to define a user-defined function. A function is a group of related statements for one or more specific task

8. del – del is used to delete or remove a target element in python. del is used to delete variables, list or dictionary elements.
The del statements look like this

Object means a type of python object. Usually, these are variables but they can be functions, list dictionaries

9. elif – elif is a keyword in python similar elseif in other languages. It is used for conditional statements and test conditions. The colon(:) at the end of the statement is required.

Output

x is less than  y

10. else – Elif is a keyword in python, it is used in conditional statements and test conditions. The colon(:) at the end of the statement required

Output

x is equal to y

11. except

12. finally

13. for – for is a keyword in Python, for looping statement. It is used to limit the number of times we want to execute.

Output
Hello sankar
Hello kanthan
Hello rajah
Hello yogan
Hello kumar

14. from

15. false – This keyword is used to represent a boolean false value. when become a statement is false “false” is  displayed

Example 1

Example 2

16. global

17. if is used in conditional statements and test conditions. The colon(:) at the end of the statement required

Output

x is greater than to y

18. import

19. in – in is used to check if the element contains a list or tuple etc….
It returns true if the value is present, it returns false if the value is not present.

another used in the forloop at python

Output
H

a
p
p
y

b
i
r
t
h
d
a
y

20. is

21. lambda

22. nonlocal

23. not –  not operator is used to invert the true value

Example not

24. or –  or operator will turn into true if any of the operands are true

Example for or

25. pass – pass is a keyword used to require implementation. pass is a null operation- noting happens when it executes.

Syntex

26. raise

27. return

28. try

29. true – This keyword is used to represent a boolean true value. When a statement is true, the word “true” is displayed.

Example

28. while – while is a keyword for looping statement. It is used to limit the number of times we want to execute

Output
10

9
8
7
6
5
4
3
2
1

Learn more about python click Python while loop and Nested while loop in Python

29. with

30. yeild

 

Suggested for you

Keyword in C language

Data type in Pyton language

Karmehavannan

Share
Published by
Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.