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

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

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.