python3
python3
Table of Contents
Print() Function
Basic Input in Python
Input() Function
String Formatting
Type Casting and Conversion
Print() Function
-----------------
The print() function is used to output text to the console.
It can take a single argument or multiple arguments separated by commas.
Example: print("Hello, World!")
Basic Input in Python
-------------------------
In Python, input is read from the console using the input() function.
input() returns a string that contains the user's input.
Example: user_input = input()
Input() Function
-----------------
The input() function reads a line of input from the console.
It returns a string that contains the user's input.
Example: name = input("What is your name? ")
String Formatting
-----------------
String formatting is a way to insert values into a string.
Python has several ways to format strings, including:
% operator: print("Hello, %s!" % name)
str.format() method: print("Hello, {}!".format(name))
f-strings (Python 3.6+): print(f"Hello, {name}!")
Type Casting and Conversion
--------------------------------
Type casting is used to convert a value from one type to another.
Python has several built-in functions for type casting, including:
int(): converts a string or number to an integer
float(): converts a string or number to a floating-point number
str(): converts a value to a string
Example: age = int(input("How old are you? "))
I hope these notes help you understand the basics of print() and input in Python!
Let me know if you have any questions or need further clarification.
Example Code
Python
# Print a message to the console
print("Hello, World!")