编程语言
首页 > 编程语言> > kaggle_python七天入门_第一天

kaggle_python七天入门_第一天

作者:互联网

文章目录

概述

kaggle第一天学习内容主要有:

  1. Python 语法(syntax)
  2. 变量赋值(variable assignment)
  3. number中的整数(int)与小数(float)
  4. 算数运算符(arithmetic operator)
  5. notebook 快捷键

1. Hello Python

Python名字是源于英国戏剧团Monty Python,他们曾表演过短剧Spam。
我们用与之相关的例子,来引出Python的学习。

spam_amount = 0
print(spam_amount)

# Ordering Spam, egg, Spam, Spam, bacon and Spam (4 more servings of Spam)
spam_amount = spam_amount + 4

if spam_amount > 0:
    print("But I don't want ANY spam!")

viking_song = "Spam " * spam_amount
print(viking_song)

我们讲上述代码拆开分析,这个简单的代码块展示了Python中许多重要方面。

spam_amount = 0
print(spam_amount)
# Ordering Spam, egg, Spam, Spam, bacon and Spam (4 more servings of Spam)

spam_amount = spam_amount + 4
if spam_amount > 0:
    print("But I don't want ANY spam!")

viking_song = "Spam Spam Spam"
print(viking_song)

本节我们不讨论太多条件语句(conditionals)

2. Numbers and arithmetic in Python 数字与算术

‘Number’ :是一个不正式的名称,数字有他自己的类型:

spam_amount = 0
type(spam_amount) # int
type(19.95) # float
Python中的基本运算:
OperaterNameDescription
a + bAdditionSum of a and b
a - bSubtractionDifference of a and b
a * bMultiplicationProduct of a and b
a / bTrue divisionQuotient of a and b
a // bFloor divisionQuotient of a and b, removing fractional parts
a % bModulusInteger remainder after division of a by b
a ** bExponentiationa raised to the power of b
-aNegationThe negative of a

计算机可以做两种除法。“True division” 和 “Floor division”

# the below lines give us a `float`
print(5 / 2)  #2.5
print(6 / 2)  #3.0

# ''//' 运算符给我们一个四舍五入到下一个整数的结果
print(5 // 2) # 2
print(6 // 2) # 3
运算顺序(order of operations)
total_height_meters = (hat_height_cm + my_height_cm) / 100
print("Height in meters =", total_height_meters)
运算的内置函数(builtin function of working with numbers)
print(min(1, 2, 3)) # 1
print(max(1, 2, 3)) # 3

print(abs(32)) # 32
print(abs(-32))# 32
print(float(10)) # 10.0
print(int(3.33)) # 3
# They can even be called on strings!
print(int('807') + 1) # 808

3. notebook快捷键

  1. ctrl + enter:运行cell
  2. Esc + a(b): 在存在的cell之前(后)增加一个cel

标签:七天,float,Spam,python,spam,kaggle,Python,amount,print
来源: https://blog.csdn.net/weixin_49340599/article/details/113110417