0% found this document useful (0 votes)
2 views

python3

This document provides an overview of the basics of the print() and input() functions in Python. It explains how to use these functions for outputting text and reading user input, along with string formatting techniques and type casting methods. Examples are included to illustrate the concepts discussed.

Uploaded by

chirag.hhs.7887
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

python3

This document provides an overview of the basics of the print() and input() functions in Python. It explains how to use these functions for outputting text and reading user input, along with string formatting techniques and type casting methods. Examples are included to illustrate the concepts discussed.

Uploaded by

chirag.hhs.7887
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Python Print() and Input Basics Notes

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!")

# Read input from the user


name = input("What is your name? ")

# Print the user's input


print("Hello, {}!".format(name))

# Convert the user's input to an integer


age = int(input("How old are you? "))
print("You are {} years old.".format(age))

You might also like