zoukankan      html  css  js  c++  java
  • python学习之语法

      看过python的语法,才知道,这中编程语言是最简洁的,比如if a==b这种判断a和b的值是否相等,其他编程语言是需要小括号的,这个就不用。

      if语句:

    cars = ['audi', 'bmw', 'subaru', 'toyota']
    for car in cars:
        if car == 'bmw':
            print(car.upper())
        else:
            print(car.title())

      上述代码中包含了for循环语句一级if语句,要特别注意冒号和缩进

      if-elif-else 结构 :

      在其他类编程语言中,大部分都是if-else if-else结构,而在python中,则是if-elif-else 结构。

    age = 12
    if age < 4:
        print("Your admission cost is $0.")
    elif age < 18:
        print("Your admission cost is $5.")
    else:
        print("Your admission cost is $10.")            

      特殊判断元素

      in判断元素是否在列表中。

    requested_toppings = ['mushrooms', 'green peppers', 'extra cheese']
    for requested_topping in requested_toppings:
        print("Adding " + requested_topping + ".")
        print("
    Finished making your pizza!")

      总结:

      对于一个熟知多种编程语言的学生,我们会很快接受这些语法,最终要的就是缩进,缩进,缩进,其他的都或多或少有了些编码的习惯。

      推荐一个网站:https://leetcode.com/problemset/all/ 在编程中熟知语法以及各类函数的使用。

      

  • 相关阅读:
    linux防火墙iptables
    etc/fstab
    EDT改成CST
    echo
    dd
    chown
    CAT
    Linux grep
    CHECKSUM比较两表字段值差异
    通过GitHub部署项目到Nginx服务器
  • 原文地址:https://www.cnblogs.com/cnyulei/p/7520982.html
Copyright © 2011-2022 走看看