You are on page 1of 3
Python Basics: Takeaways & by Dataquest Labs, Inc. - All rights reserved © 2018, Syntax COMMON ARITHMETIC OPERATORS * Parentheses 9: 6/5) 45 + Exponent ++: 6s +5 * Multiplication +: s +s * Division ys 75 * Addition 4: 545 * Subtraction ©: 5. s COMMON VARIABLE OPERATIONS * Assigning a value directly to a variable: integer_val = 5 Aloat_val = 5.0 stringval = * Assigning the result of a calculation to a variable total = 545 average = (5 +545) / 3 DISPLAYING VALUES * Displaying a value Anteger_val = 5 print(s) printCinteger_vat) print(s +5 +5) * Displaying a value's data type Anteger_val = 5 print typeCnteger_val)) LIST OPERATIONS * Creating an empty list: rine rates = (1 * Creating a list with values: ccrine_rates = (749, 371, 8, $03, 1379] * Appending a value to a list: * Accessing individual elements in a list: crine_rates = (749, 371, 8, 503, 1379] cr_first = crime rates[0] er_third = crime rates{2] * Working with the length of a list: rine rates = (749, 371, 928, 505, 1579] dength = len(crine_rates) ‘ast_elanent = crime rates{Length-1] * Accessing slices of values in a list: 5 = (789, 371, 828, 503, 1379] ‘erime_rates[@:3] # Values at ©, 1, 2 Concepts + When evaluating expressions, Python uses the order of operations rules from mathematics. + Every value in Python has a data type associated with it. The common data types are: + Strings: + Integers: 6 * Floats: 60 Resources + Documentation on all arithmetic operators + Documentation on lists

You might also like