Day1- Data Types in Python
Day1- Data Types in Python
Declaring Variables:
Explanation:
9. We declare variables x, y, name, and is_student of different data
types: integer, float, string, and boolean, respectively.
10. We print the data types of these variables using the type()
function.
11. We perform type conversion operations using functions like str(),
int(), and bool() to convert variables to different data types.
12. Finally, we print the converted variables.
Output:
Data types:
x is of type: <class 'int'>
y is of type: <class 'float'>
name is of type: <class 'str'>
is_student is of type: <class 'bool'>
Converted variables:
x_str: 10
y_int: 3
is_student_str: True
Explanation:
1. We use the input() function to get user input, which is initially
stored as a string.
2. We convert the input string to an integer using the int() function.
3. We perform an arithmetic operation (multiplication by 2) on the
converted integer.
4. Finally, we print the result.
Output (Sample):
Enter a number: 5
Twice the number is: 10