카테고리 없음

스파르타 AI-8기 TIL(9/27)

kimjunki-8 2024. 9. 27. 21:57

Reiterate statement

1. for

Ex. for a in [1,2,3]

      print(a)

 

result:

1

2

3

 

2. while

I = 0

while I < 3:

        I = I + 1

        print(I)

result

1

2

3

 

Def function

Ex.

def add(a, b): -> add(a,b) -> receiver

      return a + b

add(3,4) -> add(3,4) input

result:

7

"" and ''

 

Print

"Python is easy" -> Python is easy

"Python's favorite" -> Python's favorite

' "Python is easy," she said ' -> "Python is easy," she said

Can use \

"\"Python is very easy.\" he says" -> "Python is very easy," he says

 

When putting multiple lines into variable (\n or "' "' or ''' ''')

multiline = "I need to read\nBecause I have to"
print (multiline)

or

multiline = """ I need to read
Because I have to"""
print (multiline)

or

multiline = ''' I need to read
Because I have to'''
print (multiline)

result

-> 

I need to read
Because I have to

 

Tips

\n -> changing line

\t -> giving a space

\\ -> just to show \ itself

\' -> to show '

\" -> to show "

 

string addition or multiplication

a = "python"

b = "is good"

print ->

a + b -> python is good

a * 2 -> pythonpython

 

Index Slicing

Ex.

a = "python"
print(a[0:2])

result -> py

Meaning 0:2 -> get the text from 0 to 1(not include end number)

or can skip 0

a = "python"
print(a[:3])

result -> pyt

or

If I want to get all the texts

a = "python"
print(a[:])

result -> python

I don't have to write the number

or I also can use -

a = "python"
print(a[2:-1])

result -> tho

 

From tomorrow, I have to watch the videos again..

Good night