Python Coding basics

studied byStudied by 1 person
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 11

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

12 Terms

1

Variables and Data Types

# Strings and numbers
name = "GirlyPop"
age = 16
is_excited = True

Think of variables as cute little containers where you store data. Python supports different data types like numbers, strings (text), and booleans (true/false).

New cards
2

Lists and Dictionaries

# List: storing multiple values
outfits = ["Dress", "Jeans", "Sweater"]
print(outfits[0]) # Prints: Dress

# Dictionary: key-value pairs
wardrobe = {"top": "blouse", "bottom": "skirt"}
print(wardrobe["top"]) # Prints: blouse

Lists are like shopping bags; you can store multiple items, and dictionaries are your fashion closet where each item has a label!

New cards
3

Loops

# For loop
for outfit in outfits:
print(outfit) # Prints each outfit in the list

# While loop
count = 0
while count < 3:
print("GirlyPop Power!")
count += 1

Loops help you repeat tasks, like scrolling through Instagram, but with control. for loops go through lists, and while loops keep going until you say "stop."

New cards
4

Functions

Functions are like reusable routines. You write them once, and then you can call them anytime—like your fave skincare routine.

def get_outfit(day):
if day == "Monday":
return "Blazer and Jeans"
elif day == "Friday":
return "Party Dress"
else:
return "Casual Look"

# Call the function
today_outfit = get_outfit("Monday")
print(today_outfit) # Prints: Blazer and Jeans

New cards
5

Conditionals

weather = "sunny"

if weather == "sunny":
print("Sunglasses on, GirlyPop!")
elif weather == "rainy":
print("Time for rain boots!")
else:
print("Just go with the vibe.")

Conditional statements (if, elif, else) help you make decisions. Think of it as "Should I wear this today or not?" logic.

New cards
6

Importing Libraries

Python has built-in libraries (like your fave apps) that make life easier. For bioinformatics, you’ll probably use numpy, pandas, or biopython.

import numpy as np

# Create an array (think of it as a table of data)
data = np.array([1, 2, 3, 4])
print(data) # Prints: [1 2 3 4]

New cards
7

File Handling

# Writing to a file
with open('outfits.txt', 'w') as file:
file.write("Dress, Jeans, Sweater")

# Reading from a file
with open('outfits.txt', 'r') as file:
print(file.read()) # Prints: Dress, Jeans, Sweater

Python can read and write files. It’s like opening a document, reading it, and writing your own notes!

New cards
8

Object-Oriented Programming (OOP)

Python allows you to create your own classes. Think of it as designing your own wardrobe structure, where each piece of clothing is a unique object.

class Outfit:
def __init__(self, type, color):
self.type = type
self.color = color

def describe(self):
return f"{self.color} {self.type}"

# Creating an object
my_outfit = Outfit("Dress", "Pink")
print(my_outfit.describe()) # Prints: Pink Dress

New cards
9

Numpy

import numpy as np

# Create a matrix (like a protein sequence matrix)
protein_matrix = np.array([[1, 0, 0], [0, 1, 1], [1, 0, 1]])
print(protein_matrix)

numpy is a super popular library for numerical data and arrays. You'll use it for bioinformatics to handle protein sequences or perform computations.

New cards
10

pandas

import pandas as pd

# Create a DataFrame (like a bioinformatics dataset)
data = {'Gene': ['BRCA1', 'TP53', 'EGFR'], 'Expression': [9.5, 8.3, 7.1]}
df = pd.DataFrame(data)
print(df)

New cards
11

scikit-learn

is where the magic of machine learning happens! You'll use this for predictive models, like identifying drug targets.

from sklearn.linear_model import LinearRegression

# Simple linear regression
X = [[1], [2], [3]] # Input values
y = [1, 2, 3] # Output values
model = LinearRegression()
model.fit(X, y)
print(model.predict([[4]])) # Predicts: 4

New cards
12

Bioinformatics Tools (BioPython)

  • BioPython is designed for computational biology tasks like handling protein or DNA sequences.

from Bio.Seq import Seq

# Create a DNA sequence
dna_seq = Seq("AGTACACTGGT")
print(dna_seq) # Prints: AGTACACTGGT

# Transcribe DNA to RNA
print(dna_seq.transcribe()) # Prints: AGUACACUGGU

New cards

Explore top notes

note Note
studied byStudied by 43 people
834 days ago
5.0(1)
note Note
studied byStudied by 14 people
707 days ago
5.0(2)
note Note
studied byStudied by 3 people
674 days ago
5.0(1)
note Note
studied byStudied by 19 people
670 days ago
4.8(4)
note Note
studied byStudied by 7 people
763 days ago
5.0(1)
note Note
studied byStudied by 24 people
754 days ago
5.0(1)
note Note
studied byStudied by 31 people
99 days ago
5.0(2)
note Note
studied byStudied by 78 people
875 days ago
5.0(1)

Explore top flashcards

flashcards Flashcard (231)
studied byStudied by 24 people
276 days ago
5.0(1)
flashcards Flashcard (181)
studied byStudied by 1 person
72 days ago
5.0(1)
flashcards Flashcard (151)
studied byStudied by 16 people
483 days ago
4.0(1)
flashcards Flashcard (69)
studied byStudied by 106 people
159 days ago
5.0(1)
flashcards Flashcard (139)
studied byStudied by 15 people
358 days ago
5.0(1)
flashcards Flashcard (52)
studied byStudied by 484 people
289 days ago
4.0(5)
flashcards Flashcard (21)
studied byStudied by 18 people
530 days ago
5.0(1)
flashcards Flashcard (69)
studied byStudied by 2 people
53 days ago
4.0(1)
robot