{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']\n", "type(medical_list)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['1', '2', '3']" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list('123')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "'int' object is not iterable", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m123\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mTypeError\u001b[0m: 'int' object is not iterable" ] } ], "source": [ "list(123)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Length of list\t: 6\n", "[0]\t\t: toothache\n", "[1:5:3]\t\t: ['pimple', 'asthma']\n" ] } ], "source": [ "print('Length of list\\t:', len(medical_list))\n", "print('[0]\\t\\t:', medical_list[0])\n", "print('[1:5:3]\\t\\t:', medical_list[1:5:3])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "['toothache',\n", " 'pimple',\n", " 'myopia',\n", " 'astigmatism',\n", " 'asthma',\n", " 'flatfloot',\n", " 'headache',\n", " 'nausea',\n", " 'vomitting']" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']\n", "medical_list.append('headache')\n", "medical_list.append('nausea')\n", "medical_list.append('vomitting')\n", "medical_list" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['toothache',\n", " 'pimple',\n", " 'myopia',\n", " 'astigmatism',\n", " 'asthma',\n", " 'flatfloot',\n", " 'headache',\n", " 'nausea',\n", " 'vomitting']" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']\n", "recent_illness = ['headache', 'nausea', 'vomitting']\n", "medical_list.extend(recent_illness)\n", "medical_list" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['toothache',\n", " 'pimple',\n", " 'myopia',\n", " 'astigmatism',\n", " 'asthma',\n", " 'flatfloot',\n", " 'headache',\n", " 'nausea',\n", " 'vomitting']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']\n", "recent_illness = ['headache', 'nausea', 'vomitting']\n", "medical_list = medical_list + recent_illness\n", "medical_list" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['toothache',\n", " 'pimple',\n", " 'myopia',\n", " 'astigmatism',\n", " 'asthma',\n", " 'flatfloot',\n", " 'headache',\n", " 'nausea',\n", " 'vomitting']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']\n", "recent_illness = ['headache', 'nausea', 'vomitting']\n", "medical_list += recent_illness # 我改了這行\n", "medical_list" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1024" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "底數 = 2\n", "對數 = 10\n", "底數 **= 對數\n", "底數 # 已經不是底數的底數" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "vomitting 的位置: 8\n", "拼字正確的清單 ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomiting']\n" ] } ], "source": [ "medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting']\n", "print('vomitting 的位置:', medical_list.index('vomitting'))\n", "medical_list[(medical_list.index('vomitting'))] = 'vomiting'\n", "print('拼字正確的清單', medical_list)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2. 給你看 vomiting\n", "1. 拿出來 ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea']\n" ] } ], "source": [ "medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomiting']\n", "print('2. 給你看', medical_list.pop())\n", "print('1. 拿出來', medical_list)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pimple的位置 1\n", "拿出來給你看 pimple\n", "['toothache', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomiting']\n" ] } ], "source": [ "medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomiting']\n", "print('pimple的位置', medical_list.index('pimple'))\n", "print('拿出來給你看', medical_list.pop(medical_list.index('pimple')))\n", "print(medical_list)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "tuple" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "medical_tuple = ('toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting')\n", "type(medical_tuple)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('toothache',\n", " 'pimple',\n", " 'myopia',\n", " 'astigmatism',\n", " 'asthma',\n", " 'flatfloot',\n", " 'headache',\n", " 'nausea',\n", " 'vomitting')" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting']\n", "medical_tuple = tuple(medical_list)\n", "medical_tuple" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'vomitting'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "medical_tuple[-1]" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "'tuple' object does not support item assignment", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mmedical_tuple\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'vomiting'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" ] } ], "source": [ "medical_tuple[-1] = 'vomiting'" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }