Cell In[4], line 1 try = 5 # Watch out for reserved words ^ SyntaxError: expected ':'
POP77001 Computer Programming for Social Scientists
It is a good practice to follow usual naming convention when writing code.
my_list = [
1, 2, 3,
4, 5, 6,
]
result = some_function_that_takes_arguments(
'a', 'b', 'c',
'd', 'e', 'f',
)
income = (gross_wages
+ taxable_interest
+ (dividends - qualified_dividends)
- ira_deduction
- student_loan_interest)
There are 35 reserved words (keywords) in Python (as of version 3.9) that cannot be used as identifiers.
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) File ~/Decrypted/Git/POP77032_QTA/lib/python3.12/site-packages/pandas/compat/_optional.py:158, in import_optional_dependency(name, extra, min_version, errors) 157 try: --> 158 module = importlib.import_module(name) 159 except ImportError as err: File /usr/lib/python3.12/importlib/__init__.py:90, in import_module(name, package) 89 level += 1 ---> 90 return _bootstrap._gcd_import(name[level:], package, level) File <frozen importlib._bootstrap>:1387, in _gcd_import(name, package, level) File <frozen importlib._bootstrap>:1360, in _find_and_load(name, import_) File <frozen importlib._bootstrap>:1324, in _find_and_load_unlocked(name, import_) ModuleNotFoundError: No module named 'tabulate' The above exception was the direct cause of the following exception: ImportError Traceback (most recent call last) Cell In[3], line 2 1 # display(HTML(reserved_words.to_html(header = False, index = False))) ----> 2 Markdown(reserved_words.to_markdown(index = False, headers = ['', '', '', '', ''])) File ~/Decrypted/Git/POP77032_QTA/lib/python3.12/site-packages/pandas/core/frame.py:2983, in DataFrame.to_markdown(self, buf, mode, index, storage_options, **kwargs) 2981 kwargs.setdefault("tablefmt", "pipe") 2982 kwargs.setdefault("showindex", index) -> 2983 tabulate = import_optional_dependency("tabulate") 2984 result = tabulate.tabulate(self, **kwargs) 2985 if buf is None: File ~/Decrypted/Git/POP77032_QTA/lib/python3.12/site-packages/pandas/compat/_optional.py:161, in import_optional_dependency(name, extra, min_version, errors) 159 except ImportError as err: 160 if errors == "raise": --> 161 raise ImportError(msg) from err 162 return None 164 # Handle submodules: if we have submodule, grab parent module from sys.modules ImportError: `Import tabulate` failed. Use pip or conda to install the tabulate package.
Cell In[4], line 1 try = 5 # Watch out for reserved words ^ SyntaxError: expected ':'
Extra
str) - immutable ordered sequence of characters.s.capitalize()
s.title()
s.upper()
s.lower()
s.find(some_string)
s.replace(one_string, another_string)
s.strip(some_string)
s.split(some_string)
s.join(some_list)
Extra
s.strip().replace('--', '---').title()list) - mutable ordered sequence of elements.l.append(some_element)
l.extend(some_list)
l.insert(index, some_element)
l.remove(some_element)
l.pop(index)
l.sort()
l.reverse()
l.copy()
Extra