Chapter 2 Control Statements - BCS Guruji

Ad

Saturday, December 9, 2023

Chapter 2 Control Statements

 -Give the purpose of selection statements in Python.

Selection statements (like if, elif, and else) in Python serve the purpose of making decisions in the code. They allow the program to choose different paths or actions based on the evaluation of conditions. 


- List the types of type conversion in Python.

Implicit Type Conversion (Coercion):

Automatically performed by the interpreter.

Example: Converting an integer to a float during arithmetic operations.


x = 5

y = 2.0

result = x + y  # Implicitly converts x to float

Explicit Type Conversion (Casting):

Done by the programmer using predefined functions like int(), float(), str(), etc.

Example: Converting a string to an integer.


- Explain backward indexing in strings.

  • Write a Python program to display power of 2 using an anonymous function.

No comments:

Post a Comment