GoConqr has a new look! Let us know what you think.

Flashcards

Pie

Shez F English 38 cards

Cards in this deck (38)

  1. 1What do programs compose of1 - Modules
  2. 2What do modules contain1 - Statements
  3. 3What do statements contain1 - Expressions
    2 - These create and process objects
  4. 4What does Random.choice do1 - Given a list, will pick a random number from that list
    2 - import random
    random.choice([1,2,3,4])
  5. 5How do we do variables in pyth0n1 - Do not have to be declared
    2 - Created when you assign it a value
    counter = 100
    name = "john"
    name = [1.2.3,911]
  6. 6How do we assign a single value to multiple variables1 - shez = shaz = paz = cunt
  7. 7How do we assign a variable of a string1 - s = Spam
    Where the S in Spam is located at index 0
    p = 1
    a = 2
    m = 3
  8. 8What is a negative index of a string1 - So given s = Spam
    2 - You start at the right when using a negative index but start at 1
    3 - So m = -1
    A = -2
    P = -3
    M = -4
  9. 9What is string slicing1 - Where you slice parts of a string using the offsets.
    2 - s = "Spam"
    s[1:3] = 'pa'
    s[1:] = 'pam'
  10. 10What is Immutability1 - State cannot be changed once it has been initialized
    2 - LOL ERLANGGGGGGG
    3 - Strings are immutable in Pyth0n
  11. 11How can we change characters in an existing string1 - S = 'Lancs'
    s = 'Z' + S[1:]
    s = Zancs
  12. 12What does the .find operator dooo1 - Finds the first occurance and gets the offset value
    2 - S = lancs
    s.find(ancs)
    === 1
  13. 13What are leests1 - Like arrays but more powerf0l
    2 - No data type
    3 - No fixed size
    3 - L = [item1, item2, item3]
    4 - Results are usually lists instead of strings
  14. 14What can we do with a list1 - L = [123, 456. 789]
    L[1] =
    [456]
    2- L[:-1] - Anything but the last one
    [123, 456]
  15. 15How can we concatenate a leest1 - L + 222=
    L = [123, 456, 789, 222]
  16. 16How do we add and remove an element on a list1 - Use L.append(N1) to add to the end of a list
    2 - L.pop(indexNumber) to remove an item at a specific index
  17. 17What does the sort keyword do in a list1 - Sorts a list.
    2 - L.sort = aa, bb, cc
    3 - L.reverse = cc, bb, aa
  18. 18You can also nest a list, how do dat1 - M = [[1,2,3], [4,5,6], [7,8,9]]
    2 - M[1] --------- Get second one = [4,5,6]
    3- M[1][2]-----go to second list, pick element 3 === 6
  19. 19What is list comprehension expression1 - Powerful way to process list structures
    2 - Easy to grab rows by simple indexing because the matrix is stored in rows
    M = [[1,2,3], [4,5,6], [7,8,9]]
    Col2 = [row[1] for row in M] #Collects items in column 2
    col2 = [2,5,8]. M IS UNCHANGED!!!!!!
  20. 20How do we get and store user input1 - We have the input keyword
    2 - name = INPUT (What ur name);
    waits for input and stores it
    print(name)
  21. 21How we use if statements1 = if :
    2 - HAVE TO USE INDENTATION. Indentation is part of condition. Otherwise it is not
  22. 22What do for If else1 - If :
    Else:
  23. 23What is an ELIF1 - Allows program to choose from several possibilities in an if statement
    If :
    elif;
  24. 24What do on a while lewp1 - while :
    2 - REMEMBER TO INDENT!!!!!!!
  25. 25What do on a FOR LEWP1 - for item in sequence:
    EG
    for count in [1,2,3]
    for colour in [ red, blue, green]
  26. 26What is the format for the range function in pyth0n1 - Range (start, end, step)
    For i in range(0, 20, step)
  27. 27What is a tuple1 - Like a list but in ()
    2 - Is immutable
    3 -Cant cahnge the length or subtiture elements like a list
  28. 28Unpacking a tiple1 - If you know how many elements are in a tuple, you can assign each element a variable
    Name, Score = ("Shez", 0)
    Name = Shez
    Score = 0
  29. 29When can we use tuples instead of lists1 - Used for constants
  30. 30What are dictionaries1 - Store information in key-value pairs
    2 - {Key1: Value1, Key2:value2}
    3 - Each key is sepeated from its value by a :. Items are seperated by ,
    4 - Keys have to be unique
  31. 31How can we use a key to retrieve a value1 - num ={1: 1, 2: 2, 3:3, 4:4}
    2 - num["1"] returns 1....
  32. 32Testing a key to see if it has a value1 - if '1' in num:
    print (num[1]
    else:
    print (key not found lmao)
  33. 33Whats the split operation Dew1 - splits a string into a list of substring using delimters in the original string
    s = aaa, bbb, cccc, ddd
    s.split = ['aaa','bbb,....]
  34. 34Python program to count the number of werds and chars in the sentecesentence = “The quick brown fox jumps over the lazy dog ”
    words = sentence.split()
    print("\nWords = ", words)
    print("Word count = ", len(words))
  35. 35What are function1 - Allow you break up big program to smaller managable chunks of code
    2 - Start a function by called def
  36. 36What are global variables and constants in Python1 - Way of sharing data across all parts of the program using globals variables
  37. 37How we handle exceptions1 - WIth the try and except clause
    try:
    except
  38. 38—

Information

Description
Flashcards on Pie, created by Shez F on 16/05/2017.
Created by
Shez F
Views
2
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?