Posts

Showing posts from August, 2022

Python - Loops

  # Lone Star Development Training - Loops # LOOPS # For and while are some of the Loops that you will see in Python. A for loop is used for iterating over a standard # sequence, such as a list, tuple, dictionary, set or a string. This is more like an iterator method found in other # object oriented programming languages and less like standard for loops in other languages. # A while loop is going to keep looping until a condition has been met. # Here is a list of programming languages languages = ["Python", "C#", "Java", "Objective C", "ActionScript", "JavaScript", "TypeScript", "C++"] # in this for loop, we are going to take each one of the items in the list and print in the order # that they are in the list for x in languages: print(x) # Here is a trick that we can use to verify and test that by reversing the list order print("We are going to reverse the list here and verify that the list will...

Python Data Type - Tuple

  # Lone Star Development Training - Tuple Data Type # TUPLE # TUPLES are one of the data types that you will see in Python. Tuples are used # to store data values similar to lists. A Tuple is like a # list but it is immutable. It is also more memory efficient than lists. # mutable object - can change their state or contents # immutable object - can't change their state or contents # Tuple Methods # count() - returns the number of times a specified value occurs in a tuple # index() - Searches the tuple for a specified value and returns the position import sys sample_list = ["Python", "Java", "ActionScript", "C#", "TypeScript", "JavaScript", "Kotlin", "Objective C"] sample_tuple = ("Python", "Java", "ActionScript", "C#", "TypeScript", "JavaScript", "Kotlin", "Objective C") sample_dictionary = {1:"Python", 2:...

Python Data Types - List

  # Lone Star Development Training - List Data Type # LISTS # Lists are one of the data types that you will work with in Python. Lists can be created in multiple ways within # Python or from different packages that are available. # List Methods # Append() - Add an element to the end of a list # Extend() - Add all elements of a list to another list # Insert() - Insert an item at the defined index # Remove() - Remove an item from the list # Pop() - Removes and returns an element at the given index # Clear() - Removes all items from the list # Index() - Returns the index of the first matched item # Count() - Returns count of the number of items passed as an argument # Sort() - Sort items in a list in ascending order # Reverse() - Reverse the order of items in the list # copy() - Returns a copy of the list # Built in Functions with Lists # reduce() - apply a particular function passed in its argument to all of the # list elements stores the intermediate result and onl...

Python Data Types - Dictionary

  # Lone Star Development Training - Dictionary Data Type # DICTIONARY # Dictionaries are one of the data types that you will see often in Python. Dictionaries are used # to store data values in key value pairs. A dictionary is a # collection which is ordered, changeable and does not allow duplicates. Values # in a dictionary can be of any data type. # As of Python 3.7 dictionaries are ordered. In Python 3.6 and earlier they are unordered. # DICTIONARY METHODS # clear() - removes all elements from the dictionary # copy() - returns a copy of the dictionary # get() - returns value of specified key # items() - returns a list containing a tuple for each key value pair (KVP) # keys() - returns a list containing dict keys # pop() - remove element with specified key # popitem() - removes the last inserted KVP # update() - updates dict with specified KVP's # values() - returns list of all the values of dictionary # Create dictionary with int keys print("Language Dictionary")...

Python Data types - Floats

  # Lone Star Development Training - Float Data Type # FLOATING-POINT Numbers # Floats are one of the common data types that you will see in Python. The float type in Python designates a floating # point number. Float values are designtated with a decimal point. It is possible to specify scientific # notation with an e or E followed by a positive or negative integer. Python float values are represented # as 64-bit 'Double Precision' values as per the IEEE754 standard. # Maximum value of a float is 1.8 x 10^308. Anything over that will be indicated by string inf # Imports import math from decimal import Decimal as D # Should display value 1.79e308 print(1.79e308) # Should display inf (infinity) due to maximum capacity or limitations of the computer print(1.8e308) float1 = 1.957 print(type(float1)) print(float1) # Limitation Example 1 # Python.org website (2001-2021). Representation error. Retrieved July 1, 2022 from # https://docs.python.org/3.6/tutorial/floatingpoint.html...