Calling Functions

Functions are really important for programmers. Functions in Python are used to utilize the code in more than one place in a program. Python provides you many inbuilt functions like print(), but it also gives freedom to create your own functions. And furthermore there a many prefabricated functions in libraries. To use them you have to import them. This works in different ways:

You can import the whole library, then you must call the function by libraryName.functionName():

You can import only one function from a library, then you can call it by just using its name:

You can import only one function from a library and give it a individual name:

Basic User Input

In Python 3 you can perform user input with the input() functions.

If you want the user of your program to input a string or variable you can do it like it’s shown in the next picture:

If you want the input to be a specific type, for example a float, you can use a convert functions.

Python Basic Output

There is not just one Output functions in Python. I will show it to you with the print() function.

You can print a string or a variable:

You can print more then one string by using a comma:

If you want to ouptut a float number with a specific number of decimal places, use the round() function:

For more information I cann recommend you this website:

https://realpython.com/python-input-output/

Basic Data Types in Python

In this Post i will show you some of the basic data types in Python:

Integer
In Python 3, there is effectively no limit to how long an integer value can be. Of course, it is constrained by the amount of memory your system has, as are all things, but beyond that an integer can be as long as you need it to be:

int = 1234567894567234562782345

Float
The float type in Python designates a floating-point number. float values are specified with a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientif notation.

floatA = 4.2
floatB = .4e8

Strings
Strings are sequences of character data. The length of strings is only limited by the space on your device.
Strings are identified by single or double quotes. Strings can be empty as well.

stringA = „Hello“
stringB = „Goodbye“

Here is a source which I really liked and which gives you a nice summary with some examples for all data types:
https://www.fullstackpython.com/blog/python-basic-data-types-strings.html

Zen of Python

Today I’ll write about the Zen of Python.

The Zen of Python is a collection of 19 principles, which are are supposed to be guidelines for you while coding with Python.

Here is the list:

-Beautiful is better than ugly.
-Explicit is better than implicit.
-Simple is better than complex.
-Complex is better than complicated.
-Flat is better than nested.
-Sparse is better than dense.
-Readability counts.
-Special cases aren’t special enough to break the rules.
-Although practicality beats purity.
-Errors should never pass silently.
-Unless explicitly silenced.
-In the face of ambiguity, refuse the temptation to guess.
-There should be one, and preferably only one, obvious way to do it.
-Although that way may not be obvious at first unless you’re Dutch.
-Now is better than never.
-Although never is often better than right now.
-If the implementation is hard to explain, it’s a bad idea.
-If the implementation is easy to explain, it may be a good idea.
-Namespaces are one honking great idea—let’s do more of those!

A little easter egg is that you can display them at you interpreter with the code „import this„.

I think the zen of python is really helpful, it really helps beginners to take it easy with their first steps with Python. Especially the principle „Simple is better than complex“ helps not think too nested.

Python: Fun with Numbers

In this Article I’ll show you diverse functions to calculate in Python.

The first thing you can see is that the user has to define A & B with an „input„. Before that you can see „int„, it stands for integer. So the user is only allowed to put in whole numbers without decimal place. It’s also shown as a comment behind those lines. Comments are easily done by putting a „#“ infront of your comment.

I think that the next three functions explain themselves. The fourth one (line 16 in the picture) is an integer based divison. It means the result of this devision shows only the first figure, without the decimal numbers. It’s done by a double „//„.

With the last function (line 19) „divmod“ you can do an integer based divison and it shows you the remainder of that division. These two function show you the result: „print(result[0])“ & „print(result[1])„. First one shows you the result of the integer based divison, the second one shows you the remainder of that divison. Because I did the integer based divison already I only used the „print(result[1])

That it is how it looks like when you run it:

Thanks for reading my Blog!

Erstelle eine Website wie diese mit WordPress.com
Jetzt starten