[CS] 1, 2, 3 ~ 6

Joy·2020년 7월 6일
0

1. Introduction to Programming

Learn Python: Syntax, function


2.Development Skills

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 directory
  • cd ../../../
  • $ 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

setup

Bash

Bourne-Again SHell : one of Command Line Interfaces (CLIs)

to use Bash in window: install Git Bash

Basic git Workflow

Git

: a software that allows you to keep track of changes made to a project over time.

git commands

  • git init : start new git project
  • git status
  • git add filename :
  • git diff filename :
  • q : exit
  • git commint -m
  • git log

3. Flow, Data, and Iteration

4

.

5

Modules

Three different ways to import modules:

# First way
import module
module.function()

# Second way
from module import function
function()

# Third way
from module import *
function()

import filename 로 파일 import 가능. 그럼 파일 안에 함수 사용 가능.

random module

import random

# random int from given range
random.randint(start, end)

#random element from a sequence
random.choice(seq)

Dictionary

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
  • .get()

dic.get("key", "if None: return this"optional)
  • .pop() :remove key-value pairs
dic.pop('key')

class

  • .__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"
  • class variables 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
profile
roundy

0개의 댓글