bash Flashcards

1
Q

split

A

“word”.split() # by default ‘ ‘

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

search by file

A

import glob
print(glob.glob(‘*.js’))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

os

A

os.getcwd()

print( os.listdir())

joined_path = os.path.join(a, b)

consulta = “dir”
bb=os.system(consulta)

os.mkdir(‘new_carpet’) #create cartpet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

dicctionary
one= {
“nombre”: “Juan”,
“edad”: 30,
“direccion”: {
“calle”: “Mayor”,
“numero”: 123,
“ciudad”: “Madrid”
}
}

A

well:
one[“nombre”]
one[“nombre”][“direccion”]

wrong: js
one.nombre
one.nombre.direccion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

view installed packages

A

pip list

www=hello world 123 => www=hello%world%123

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

python -m venv venv
.\venv\Scripts\activate

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

document.write(“Hello, World!”)

with open(“aa.txt”,”w”) as document:
document.write(“\n Hello, World!sfsdfas”)

with open(“aa.txt”,”a”) as document:
document.write(“\n Hello, World!sfsdfas”)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Who created ??

A

Guido van Rossum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

time => delay

A

impor time

time.sleep(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

import since other file

A

===== one.py
def sumar (a,b):
return a+b
===== two.py
import one

print(one.sumar(10,209)) // 309

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

import random

def get_clue():
words = [‘elefante’, ‘león’, ‘jirafa’, ‘hipopótamo’, ‘mono’]
random_word = random.choice(words)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

function // give variables

A

def suma(a:int,b:int):
return a+b

print(suma(10, 20))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

enumerate

A

frutas = [‘manzana’, ‘banana’, ‘cereza’, ‘durazno’]

for i, fruta in enumerate(frutas):
print(f”Fruta {i+1}: {fruta}”)

=>
Fruta 1: manzana
Fruta 2: banana
Fruta 3: cereza
Fruta 4: durazno

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

dividir el nombre del archivo // y la extensión del archivo

A

nombre, extension = os.path.splitext(archivo)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

change name

A

os.rename(os.path.join(directorio, archivo),os.path.join(directorio2, nuevo_nombre))

17
Q

eliminar carpeta

A

import shutil

shutil.rmtree(“images”)

18
Q

show all the files

A

glob.glon(“*”)

19
Q

os.remove() => delete all the files

A

example1

os.remove(one.txt)

“example2
for i in glob.glob(‘*’):
if i == ‘one.py’:
continue
os.remove(i)

20
Q

comment code block

A

’’’
aaaaaaaaaaaaaaaa
‘’’

20
Q

random
random.choice

A

import random
def one():
print( random.choice([“Si”,”No”]))

21
Q
A