Python Beginner Class — 1.02 User Input and Deep into Data Types

Joker Hacker
4 min readJul 7, 2021
Python Calculator (CLI) code from github.com/fsociety-22/calc-python/
Calculator Code from https://github.com/Fsociety-22/calc-python/blob/main/main.py

Hello Everyone

Joker here again with the new episode of our python series. It is been two weeks, I think, since the last post of our series. In this episode, we will be seeing about User Input and more deep into data types we learned in the last episode.

User Input in Python

Python allows user input for user-friendly coding, Already you would be wandering about the code image in the top, That’s just my calculator CLI code. It will be useful for reference.

Assume that you are running a data science project and using env or string data in the code, and now you want to change the variable at some point with your preference or at live time, That’s where input() method comes handy.

No need to define the variable always, for some times ask the user for the input at their choice.

Code Example:

As you see here, the code is simple and asking the user to input in 3rd line, and it stores the input data in name string.

For teaching purpose, I printed the code with the name string data type

I have added how the output will look alike, the input method will ask for the user input, and it waits until the users gives the input or hits enter.

Sounds cool right? Yeah, this method and print function can make any Python Code a better and great one.

Application of Data Types

Strings

As we saw earlier in the last post of our blog, strings are nothing but words or paragraphs.

String method has a lot of built-in methods like split(), replace()., etc.
we will be seeing about some popular one

len() — function returns the length of the string.
split() — splits each word into a list.
replace() — replace a certain word with another.
strip() — Removes spaces between at the beginning and at the end of the string.
startswith() — Returns true if the certain string starts with.
endswith() — Returns true if a certain word ends with.

List

append() — adds an element at the end of the list
clear() — removes all the elements from the list.
copy () — returns a copy of the list.
count() — returns the number of elements with the specified value.
extent() — add the elements of a list, to the end of the current list.
insert() — adds an element at the specified position.
remove() — removes the first item with the specified value.
reverse() — Reverses the order of the list.
sort() — Sorts the list.

Dictionary

clear() — Removes all the elements from the dictionary
copy() — Returns a copy of the dictionary
fromkeys() — Returns a dictionary with the specified keys and value
get() — Returns the value of the specified key
items() — Returns a list containing a tuple for each key value pair
keys() — Returns a list containing the dictionary’s keys
pop() — Removes the element with the specified key
popitem() — Removes the last inserted key-value pair
setdefault() — Returns the value of the specified key. If the key does not exist: insert the key, with the specified value
update() — Updates the dictionary with the specified key-value pairs
values() — Returns a list of all the values in the dictionary

Set

add() — Adds an element to the set
clear() — Removes all the elements from the set
copy() — Returns a copy of the set
difference() — Returns a set containing the difference between two or more sets
difference_update() — Removes the items in this set that are also included in another, specified set
discard() — Remove the specified item i
ntersection() — Returns a set, that is the intersection of two or more sets intersection_update() — Removes the items in this set that are not present in other, specified set(s)
isdisjoint() — Returns whether two sets have a intersection or not
issubset() — Returns whether another set contains this set or not
issuperset() — Returns whether this set contains another set or not
pop() — Removes an element from the set
remove() — Removes the specified element
symmetric_difference() — Returns a set with the symmetric differences of two sets
symmetric_difference_update() — inserts the symmetric differences from this set and another
union() — Return a set containing the union of sets
update() — Update the set with another set, or any other iterable

Reference and Credits — w3schools.

I hope you will look more in deep with the reference I gave above. In the next class we will see about If-Else statement then with loops.

--

--