日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python编程教程交互式联系_Python Koans交互式教程

發布時間:2025/3/12 python 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python编程教程交互式联系_Python Koans交互式教程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Python Koans是一個學習Python編程語言的交互式教程,通過解決當中的問題來更深刻地理解Python。本系列文章為在此項目的學習中的問題解決方案及思考

Lesson 2 String

字符串是 Python 中最常用的數據類型。我們可以使用引號’或”來創建字符串。

about_strings.py

#!/usr/bin/env python

# -*- coding: utf-8 -*-

from runner.koan import *

class AboutStrings(Koan):

def test_double_quoted_strings_are_strings(self):

string = "Hello, world."

self.assertEqual(True, isinstance(string, str))

def test_single_quoted_strings_are_also_strings(self):

string = 'Goodbye, world.'

self.assertEqual(True, isinstance(string, str))

def test_triple_quote_strings_are_also_strings(self):

string = """Howdy, world!"""

self.assertEqual(True, isinstance(string, str))

def test_triple_single_quotes_work_too(self):

string = '''Bonjour tout le monde!'''

self.assertEqual(True, isinstance(string, str))

def test_raw_strings_are_also_strings(self):

string = r"Konnichi wa, world!"

self.assertEqual(True, isinstance(string, str))

def test_use_single_quotes_to_create_string_with_double_quotes(self):

string = 'He said, "Go Away."'

self.assertEqual('He said, "Go Away."', string)

def test_use_double_quotes_to_create_strings_with_single_quotes(self):

string = "Don't"

self.assertEqual("Don't", string)

def test_use_backslash_for_escaping_quotes_in_strings(self):

a = "He said, "Don't""

b = 'He said, "Don't"'

self.assertEqual(True, (a == b))

def test_use_backslash_at_the_end_of_a_line_to_continue_onto_the_next_line(self):

string = "It was the best of times,n

It was the worst of times."

self.assertEqual(52, len(string))

def test_triple_quoted_strings_can_span_lines(self):

string = """

Howdy,

world!

"""

self.assertEqual(15, len(string))

def test_triple_quoted_strings_need_less_escaping(self):

a = "Hello "world"."

b = """Hello "world"."""

self.assertEqual(True, (a == b))

def test_escaping_quotes_at_the_end_of_triple_quoted_string(self):

string = """Hello "world""""

self.assertEqual("""Hello "world"""", string)

def test_plus_concatenates_strings(self):

string = "Hello, " + "world"

self.assertEqual("Hello, world", string)

def test_adjacent_strings_are_concatenated_automatically(self):

string = "Hello" ", " "world"

self.assertEqual("Hello, world", string)

def test_plus_will_not_modify_original_strings(self):

hi = "Hello, "

there = "world"

string = hi + there

self.assertEqual("Hello, ", hi)

self.assertEqual("world", there)

def test_plus_equals_will_append_to_end_of_string(self):

hi = "Hello, "

there = "world"

hi += there

self.assertEqual("Hello, world", hi)

def test_plus_equals_also_leaves_original_string_unmodified(self):

original = "Hello, "

hi = original

there = "world"

hi += there

self.assertEqual("Hello, ", original)

def test_most_strings_interpret_escape_characters(self):

string = "n"

self.assertEqual('n', string)

self.assertEqual("""n""", string)

self.assertEqual(1, len(string))

總結

以上是生活随笔為你收集整理的python编程教程交互式联系_Python Koans交互式教程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。