Python: if…else [Flow Control]

if Condition Output: For example, check the following example- Output: if…else Output: if…elif…else Output: Nested if…else Output: Example #1: Discount Calculation Output: Run the script and enter price “100”- Rerun the script and enter price “999”- Rerun the script and enter price “5000”-

Python: I/O [Input/Output]

Use the input function to take input from user(in the terminal). The input() function will wait for the user to enter some data- Output: If we check the type of data obtained from input() function, it is ‘str’. No matter what we enter, then input function will take it as string. We can provide some … Read more

Python: Dictionary [Data Type]

Dictionary in Python is a collection of key/value pairs. Dictionaries use keys(labels) to store item/value references, instead of numbered index. Python Dictionary is a unordered and mutable collection of Zero(0) or more key/value pairs. Only hashable objects can be used as key in a Dictionary. Dictionary items are not ordered, and are not stored in … Read more

Python: List [Data Type]

List in Python is a data type that stores a collection of data, of one or more types. Python list is mutable. Lists are ordered collections of items. Items in the list store the order of each item.

Python: Integer [Data Type]

Integer in Python represents whole numbers, without any fractional part. An integer can be positive, negative, or zero. NOTES Max size of an integer in Python depends on the memory of the machine. Integers can be very large in Python, though working with a very large integer will be very slow. If the integer in … Read more

Python: String [Data Type]

What is a String? String in Python is- Examples of String Create String Use “str” function to create a new string. If no value is provided to “str” function then an empty string is created- Output: We can wrap a sequence of characters with single or double quotes to define a string literal. Output: Multi-line … Read more

Python: Data Types

General Data Types Data Type Python Type Immutable & Hashable Boolean bool Yes Integer int Yes Floating point number float Yes String str Yes Bytes bytes Yes Collection Data Types Data Type Python Type Immutable & Hashable Tuple tuple Yes Set set No Frozen Set frozenset Yes List list No Dictionary dictionary No