Tag Archives: programming

Loops in Swift Code | 循环 Xúnhuán

Hello everybody! Today in class we have learned 👩‍🏫 how to write loops 循环 (Xúnhuán) in Swift code 👩‍💻. We learned two kinds of loops ➰.

The first type of loop that we learned was a loop ➿ that repeats itself for a certain amount of times⏲. We learned 🏫 how to write this kind of loop in Swift code. Here’s an example.

for i in 1 … 4 {
moveForward()
turnRight()
moveForward()
turnLeft()
}

for i in 1 ... 4 {
moveForward()
turnRight()
moveForward()
turnLeft()
}

Next we learned another loop ⭕ that repeats itself until the condition is false🙅‍♀️. This loop is called a while loop. Here’s an example.

while thereIsACoin {
moveForward()
collectCoin()
}

while thereIsACoin {
moveForward()
collectCoin()
}

In a while loop the loop will go forward ⏩ and collect the coin 💰 nonstop until the is no more coins ☹ in front of the coin collecter to collect. This is what we have accoplished today in class 👩‍🎓👨‍🎓.

We will learn much more very soon. Goodbye!!😃😃

In the meantime, please do your homework, and use the Swift documentation (aka “instructions”).

Saving Ipython script history

%save sessionName linesToKeep

This will save script in line numbers you specify in linesToKeep,for example, 1-20 34-50 64 into a file called “sessionName.py” in your current working directory.

If you are not so specific on which lines you want to keep, you can save everything.

%save sessionName ~0/

This saves everything from the current session, denoted as “~0″ into file “sessionName.py” in your cwd (current working directory).

%save pastSession ~1/

This saves everything from the past session, denoted as “~1” into file “pastSession.py” in your cwd.

Python Data Types | Python 数据类型

Python type NumPy type pandas dtype Usage
str string_, unicode_ object Text
int int_, int8, int16, int32, int64, uint8, uint16, uint32, uint64 int64 Integer numbers
float float_, float16, float32, float64 float64 Floating point numbers
bool bool_ bool True/False values
datetime64[ns] datetime64 Date and time values
timedelta[ns] Differences between two datetimes
category Finite list of text values

Note that what is “str” in Python is called “object” in pandas. This is a potential source of confusion (isn’t everything in Python an object?).

error: Content is protected !!