{"id":212,"date":"2022-09-13T21:40:16","date_gmt":"2022-09-13T13:40:16","guid":{"rendered":"https:\/\/islandtropicaman.com\/wp\/?p=212"},"modified":"2022-10-03T09:45:25","modified_gmt":"2022-10-03T01:45:25","slug":"python-tutorial-chapter-3","status":"publish","type":"post","link":"https:\/\/islandtropicaman.com\/wp\/2022\/09\/13\/python-tutorial-chapter-3\/","title":{"rendered":"Python Tutorial &#8212; Chapter 3"},"content":{"rendered":"<p>In this chapter, I am going to show you all how to create a python variable. <\/p>\n<p>Python variable does not have a fixed type which means you can actually change the variable type by first assigning it to a number but later changing it to a string, Python will not complain about this!<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\naname = &quot;Hello, World&quot;\r\nprint(aname) # Hello World\r\naname = 10\r\nprint(aname) # 10\r\n<\/pre>\n<p>If you want to use the Python variable which is outside of a function within that function itself then you will need to declare it as a global variable within the function.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nvalue = 5\r\ndef print_value():\r\n    global value\r\n    value += 1\r\n    print(value)  # increase the value of a variable by 1 which is equal to 6\r\n<\/pre>\n<p>You can specify the data type of a variable with casting but basically, it is the same outcome as before if you change it later to a string because Python does not have type safety like Java or C!<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nvalue = int(10)\r\nprint(value) # 10\r\nvalue = 13\r\nprint(value) # 13\r\nvalue= &quot;Hello World!&quot;\r\nprint(value) # Hello World!\r\n<\/pre>\n<p>That is it, I will start to load you with a complex tutorial but as always let us starts it with this easy one first!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this chapter, I am going to show you all how to create a python variable. Python variable does not have a fixed type which means you can actually change the variable type by first assigning it to a number but later changing it to a string, Python will not complain about this! aname =&#8230;<\/p>\n<p class=\"more-link-wrap\"><a href=\"https:\/\/islandtropicaman.com\/wp\/2022\/09\/13\/python-tutorial-chapter-3\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;Python Tutorial &#8212; Chapter 3&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,72],"tags":[57],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-python","category-python-tutorial","tag-python-variable"],"blog_post_layout_featured_media_urls":{"thumbnail":"","full":""},"categories_names":{"8":{"name":"Python","link":"https:\/\/islandtropicaman.com\/wp\/category\/python\/"},"72":{"name":"Python Tutorial","link":"https:\/\/islandtropicaman.com\/wp\/category\/python-tutorial\/"}},"tags_names":{"57":{"name":"python variable","link":"https:\/\/islandtropicaman.com\/wp\/tag\/python-variable\/"}},"comments_number":"0","_links":{"self":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/comments?post=212"}],"version-history":[{"count":2,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":214,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/212\/revisions\/214"}],"wp:attachment":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/categories?post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/tags?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}