1/5
## Inputs and Strings In this lesson, we're going to learn about how to get user input and work with strings in Python. We can ask users for information by using the `input()` command. Let's create a new code section and write the following: ```python input("what is your name?") ``` We can then execute the cell, and see how Python is prompting us to enter our name. Let's type "Patrick" in the box and hit enter. It will display the input we provided. We can save the user's input into a variable. We can do that with this code: ```python name = input("what is your name?") print("My name is " + name) ``` Python is again prompting us to enter a name. If we enter "Patrick" and execute the code, it will print out: ```python My name is Patrick ``` The plus sign in the code is a concatenation operator. This is a way of combining strings together. We can also use something called an "f-string" to combine strings. Let's add the following to the existing code section: ```python print(f"{name} is my name") ``` Now, when we execute the cell, it will prompt us for a name. If we enter "Patrick", the code will output: ```python My name is Patrick patrick is my name ``` Let's break down this code. We're using `print()` to display a string. We're starting our quotes with the letter "f", which is used to denote an f-string. Inside our quotes, we have a set of curly brackets that contain the variable name. The f-string will take the value of the variable that we entered as input and insert it into the f-string. In this case, the value of the `name` variable is "Patrick", so it's inserted into the curly brackets.
A practical guide to taking user inputs and using f-strings for formatting. This lesson covers the fundamentals of collecting information from users, saving it to variables, and combining it with other strings using f-strings for better readability.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on January 14, 2025
Duration: 2h 20min
Duration: 1h 51min
Duration: 58min
Duration: 2h 23min
Duration: 53min
Duration: 2h 24min
Duration: 28min
Duration: 1h 54min
Duration: 11min
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on January 14, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar