using the command line by learning how to navigate directories and files
$
: shell prompt.
root directory : first directory in the filesystem
commands :
$ ls
: lists” the files and folders inside it$ pwd
: print working directory$ cd
: change directory$ cd ..
: move up one directorycd ../../../
$ cd ../dir_name
: change dir to dir_name$ mkdir dir_name
: new dir$ touch filename.filetype
creates a new file inside the working directory
touch media/popular.txt
Bourne-Again SHell : one of Command Line Interfaces (CLIs)
to use Bash in window: install Git Bash
: a software that allows you to keep track of changes made to a project over time.
git commands
git init
: start new git projectgit status
git add filename
:git diff filename
:q
: exitgit commint -m
git log
.
# First way
import module
module.function()
# Second way
from module import function
function()
# Third way
from module import *
function()
import filename
로 파일 import 가능. 그럼 파일 안에 함수 사용 가능.
import random
# random int from given range
random.randint(start, end)
#random element from a sequence
random.choice(seq)
my_dictionary = {"song": "Estranged", "artist": "Guns N' Roses", key : value}
my_dictionary["song"] = "Paradise City"
merging dics
dict1.update(dict2)
accession methods
ex_dict.keys()
ex_dict.values()
ex_dict.items() : tuple로 keys, values
dic.get("key", "if None: return this"optional)
dic.pop('key')
.__init__()
: called every time the class is instantiated
repr() : tell Python what the string representation of the class should be
class Employee:
def __init__(self, name):
self.name = name
def __repr__(self):
return self.name
# Dog class
class Dog:
# Method of the class
def bark(self):
print("Ham-Ham")
# Create a new instance
charlie = Dog()
# Call the method
charlie.bark()
# This will output "Ham-Ham"
instance.variable
class my_class:
class_variable = "I am a Class Variable!"
x = my_class()
print(x.class_variable) #I am a Class Variable!
__main__
identifier used to reference the current file context