DEV Community

Cover image for Python for Beginners - Part 2 - Input, Error and String
LUCIANO DE SOUSA PEREIRA
LUCIANO DE SOUSA PEREIRA

Posted on • Originally published at lucianopereira.netlify.com

2

Python for Beginners - Part 2 - Input, Error and String

python_titulo
Second part of articles about the Microsoft's Python for Beginners series.
All the examples from the playlist are available in this GitHub repository: Python Examples.

Objective

You will learn about the input function, runtime error and operations with string.
A Python file was created to demonstrate each example.

Topics

input.py

If you want the user interaction to obtain a value, use the input function.
Ex: A variable receives the result of an input and has its value printed.

code01

Running the example:

python .\examples\input.py

The result:

code02

error.py

How a runtime error is shown.
Ex: Multiple math operations are done sequentially until an error occurs.

code03

Running the example:

python .\examples\error.py

The result:

code04

An error occured at line 8 because it was not possible to divide by zero.

strings.py

Strings have many functionalities similar to JavaScript, but with lesser code.
Ex: Using multiple string functions.

code05

Running the example:

python .\examples\strings.py

The result:

code06

Next

You will learn how to make operations with numbers, dates and how to handle errors.

Video References

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (3)

Collapse
 
sinewalker profile image
Mike Lockhart • Edited

Does anyone else see the bug in this example?

I like the series though

Collapse
 
lucianopereira86 profile image
LUCIANO DE SOUSA PEREIRA

Thanks for the interest.
What bug do you see?

Collapse
 
sinewalker profile image
Mike Lockhart • Edited

In strings.py, full_name will always be "Luciano Pereira".

But I don't want to give away why: it's good for a beginner to figure it out themselves. For this reason, I also feel it would actually be good to leave the bug there, don't fix it for the post 🙂

Here is a hint: Try running it and entering another name, then do a "desk check" or step through with Code's debugger and see if you can spot it.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay