Python notes 01

  1. Explain Variables
    Variables are used to store values

    Example: age = 23

    Integer 23 is stored in the Variable age
  2. What are Strings?
    A string is a series of characters, surrounded by single or double quotes.
  3. What is Concatenation?
    Concatenation is the combining of strings.

    • - first_name = 'albert'
    • - last_name = 'einstein'
    • - full_name = first_name + ' ' + last_name
    • - print(full_name)

    >>>albert einstein
  4. What are the Data Types in Python?
    • - Strings
    • - Numbers (integer, floats, complex)
    • - Boolean
    • - Lists
    • - Tuple
    • - Dictionaries
    • - Set
  5. What are the requirements for a Variable name?
    Variable names can contain only letters, numbers, and underscores.

    They can start with a letter or an underscore, but not with a number. For instance, you can call a variable message_1 but not 1_message.

    Spaces are not allowed in variable names, but underscores can be used to separate words in variable names. For example, greeting_message works, but greeting message will cause errors.

    Python is case-sensetive, as such:

    message = "Hello."

    Message = "Hello, to you."

    These are two different variables, that when called will give differing values.
  6. What is a traceback?
    A record of where the interpreter ran into trouble when trying to execute your code.
  7. Explain the title() method in regards to strings
    The title() method modifies the string by capitalizing the first letter of every word in a string.

    • string = "jOeY mArLeY"
    • print(string.title())
    • >>>"Joey Marley"
  8. What is a Comment ( # ) in coding?
    Notes left within the code the are not processed.

    Left as reminder/explanations for the code
  9. What is an Escape Character?
    In Python strings, the backslash " \ " is a special character which invokes an alternative interpretation on subsequent characters in a character sequence.

    Example: string = ‘I don\’t love Mondays.’ # apostrophe can be used without issue due to the escape character

    Examples of Escape Sequences ( \n ) and ( \t ).
  10. What is a Statement in Python programming?
    Logical lines within the program

    Two (2) statements:

    • x = 3   # Statement number 1
    • print(x)  # Statement number 2
  11. Explain the upper() method in regards to strings
    Changes the case of a character (letter) in a string.

    From lowercase to uppercase.

    If letter is already uppercase, no effect.
  12. Explain the lower() method in regards to strings
    Changes the case of a character (letter) in a string.

    From uppercase to lowercase.

    If letter is already lowercase, no effect.
  13. What is a Literal Constants?
    Data that always represents itself

    • Example: Integer 5 is always 5
    • It does not contain data/information regarding another

    • Strings are the same
    • Example: "Hello world"
  14. What are Lists?
    A list is a collection of items in a particular order.

    In Python, square brackets ( [] ) indicate a list, and individual elements in the list are separated by commas.

    Items in the List are indexed starting from zero (0, 1, 2, 3) and left to right.

    Example: list = [‘car’, ‘boat’, ‘plane’, ‘train’]

    NOTE: Use plural names for lists, to make your code easier to read.
  15. How can you Access/View an element/item from a List?
    Individual elements in a list are accessed according to their position, called the index.

    The index of the first element is 0, the index of the second element is 1, and so forth. Negative indices refer to items at the end of the list.

    To get a particular element, write the name of the list and then the index of the element in square brackets.

    users = ['val', 'bob', 'mia', 'ron', 'ned']

    • Getting the first element:
    • first_user = users[0]
    • >>>print(first_user)
    • >>>'val'

    • Getting the second element:
    • second_user = users[1]
    • >>>print(second_user)
    • >>>'bob'

    • Getting the last element:
    • newest_user = users[-1]
    • >>>print(newest_user)
    • >>>'ned'
  16. What is an IF statement?
    The IF statement is a test for particular conditions.

    Example:

    • if test expression:
    •     statements()
Author
faker1010
ID
346709
Card Set
Python notes 01
Description
Python notes
Updated