Posts

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...

Python Data Types - Int

  # Lone Star Development Training - Int Data Types # INTEGERS (INTS) # Ints are one of the most common data types that you will see in Python. # They are numbers without decimals and can be positive, negative, or zero. # Python also supports numbers with decimals, but they are classified as a different # data type and will be covered later. # Examples my_int1 = 0 my_int2 = 55 my_int3 = -10 # Print each of the int examples above print(my_int1) print(my_int2) print(my_int3) # Now that we have introduced two data types, if you have a variable, and you're not sure what # the type of the variable is, you can use the print() function combined with the type() function # as shown in the example below. variable1 = '25' variable2 = 25 # When we print the type of variable1, we will get a statement that declares it a string. # These are the variable types that you worked with over the last two sessions. print(type(variable2)) # Now, print the type of variable2, and see how it dif...

Python Data Types - String

  # Lone Star Development Training - String Data Type # STRINGS # Strings are one of the data types that you will see the most. Strings can be created in multiple ways within # Python. You can use single, double or triple quotes. Generally double quotes are used for string representation and # single quotes are used for regular expressions, sql, or similar other needs. # Examples my_string1 = "Welcome to the Lone Star Development Python Training!" my_string2 = 'Welcome to Lone Star\'s Development Python Training!' my_string3 = "Welcome to Lone Star's Development Python Training!" my_string4 = "Welcome to 'Lone Star'" my_string5 = "Welcome to \"Lone Star\"" my_string6 = """This is a multi-line string so that it can span over several lines in the IDE.""" my_string7 = "This is a string that is going to wrap if it is oversized. This is different than a " \ ...