2 min read•june 24, 2024
and functions are essential for interacting with users and managing data flow in Python programs. These functions allow you to display information, collect user input, and convert data types for calculations.
Understanding how to use print() and effectively is crucial for creating interactive programs. You'll learn to customize output, handle user input, and convert data types to perform operations, laying the foundation for more complex programming tasks.
print()
displays output to the console ()[sep](https://www.fiveableKeyTerm:sep)
parameter
print("Hello", "world", sep="-")
outputs "Hello-world"[end](https://www.fiveableKeyTerm:end)
parameter
print("Hello", end="")
outputs "Hello" without a newlineprint("Hello", end=" ")
outputs "Hello " with a space instead of a newline[\n](https://www.fiveableKeyTerm:\n)
for newline, [\t](https://www.fiveableKeyTerm:\t)
for tabprint("Hello\nworld")
outputs "Hello" on one line and "world" on the nextinput()
gets input from the user via the console ()input()
to a variable to store the user's input
name = input("Enter your name: ")
prompts the user and stores the input in name
age = input("Enter your age: ")
prompts with "Enter your age: "input()
[int](https://www.fiveableKeyTerm:int)()
converts input to an integer
num = int(input("Enter a number: "))
converts input to integer and stores in num
[float](https://www.fiveableKeyTerm:Float)()
converts input to a floating-point number
price = float(input("Enter the price: "))
converts input to float and stores in price
[TypeError](https://www.fiveableKeyTerm:TypeError)
result = "10" + 5
raises an error (cannot add string and integer)try-except
block
[ValueError](https://www.fiveableKeyTerm:ValueError)
exceptions when converting input to numerical data typestry: age = int(input("Enter your age: ")) except ValueError: print("Invalid input. Please enter a valid integer.")