

{"id":116529,"date":"2023-09-07T19:00:30","date_gmt":"2023-09-07T13:30:30","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=116529"},"modified":"2023-09-07T19:03:27","modified_gmt":"2023-09-07T13:33:27","slug":"kotlin-when-expression","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/","title":{"rendered":"Kotlin When Expression with Examples"},"content":{"rendered":"<p>Kotlin, a contemporary programming language, empowers developers with a plethora of efficient features. Among these features, the &#8216;when&#8217; expression stands out as a robust decision-making tool. In this article, we will explore Kotlin&#8217;s &#8216;when&#8217; expression in depth, examining its syntax and demonstrating its effectiveness through relevant code snippets and examples.<\/p>\n<h3>Kotlin When Expression Syntax and Usage:<\/h3>\n<p>The &#8216;when&#8217; expression in Kotlin can be likened to an advanced version of the traditional &#8216;switch&#8217; statement found in other programming languages. It boasts a simple and flexible syntax, enabling developers to handle multiple conditions concisely and readably. Let&#8217;s take a look at the fundamental structure of a &#8216;when&#8217; expression:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">when (variable) {\r\n    condition1 -&gt; {\r\n        \/\/ Code block executed when condition1 is met\r\n    }\r\n    condition2 -&gt; {\r\n        \/\/ Code block executed when condition2 is met\r\n    }\r\n    \/\/ Additional conditions and code blocks can be added\r\n    else -&gt; {\r\n        \/\/ Code block executed when none of the conditions are met\r\n    }\r\n}\r\n<\/pre>\n<p>The &#8216;when&#8217; expression commences with the keyword &#8216;when&#8217;, followed by the variable or expression to be evaluated. Each condition is specified using the &#8216;-&gt;&#8217; operator, followed by the code block to be executed when the condition is satisfied. The &#8216;else&#8217; branch, although optional, serves as a fallback when none of the conditions match.<\/p>\n<p><strong>Example 1:<\/strong> <strong>Handling Different Input Types in Kotlin<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun handleInput(input: Any) {\r\n    when (input) {\r\n        is Int -&gt; println(\"Hey Mugdha! The input is an integer.\")\r\n        is String -&gt; println(\"Hey Mugdha! The input is a string.\")\r\n        is Double -&gt; println(\"Hey Mugdha! The input is a double.\")\r\n        else -&gt; println(\"Hey Mugdha! The input type is unknown.\")\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Input:<\/strong><\/p>\n<p>&#8220;Hello&#8221;<\/p>\n<p><strong>Output: <\/strong><\/p>\n<div class=\"code-output\">Hey Mugdha! The input is a string.<\/div>\n<p>In this example, the &#8216;when&#8217; expression is utilized to determine the type of the &#8216;input&#8217; parameter. Depending on the type, an appropriate message is displayed.<\/p>\n<p><strong>Example 2:<\/strong> <strong>Simplifying Ranges<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun evaluateScore(score: Int) {\r\n    val grade = when (score) {\r\n        in 90..100 -&gt; \"A\"\r\n        in 80 until 90 -&gt; \"B\"\r\n        in 70 until 80 -&gt; \"C\"\r\n        in 60 until 70 -&gt; \"D\"\r\n        else -&gt; \"F\"\r\n    }\r\n    println(\"Dear Mugdha, your grade is $grade.\")\r\n}\r\n<\/pre>\n<p><strong>Input<\/strong>: 85<\/p>\n<p><strong>Output<\/strong>:<\/p>\n<div class=\"code-output\">Your grade is B.<\/div>\n<p>In this example, the &#8216;when&#8217; expression is employed to calculate Mugdha&#8217;s grade based on her score. Utilizing ranges, the code becomes more concise and understandable.<\/p>\n<p><strong>Example 3:<\/strong> <strong>Enum Handling in Kotlin<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">enum class DayOfWeek {\r\n    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY\r\n}\r\n\r\nfun getWeekdayName(day: DayOfWeek) {\r\n    val name = when (day) {\r\n        DayOfWeek.MONDAY -&gt; \"Monday\"\r\n        DayOfWeek.TUESDAY -&gt; \"Tuesday\"\r\n        DayOfWeek.WEDNESDAY -&gt; \"Wednesday\"\r\n        DayOfWeek.THURSDAY -&gt; \"Thursday\"\r\n        DayOfWeek.FRIDAY -&gt; \"Friday\"\r\n        DayOfWeek.SATURDAY -&gt; \"Saturday\"\r\n        DayOfWeek.SUNDAY -&gt; \"Sunday\"\r\n    }\r\n    println(\"Hello Mugdha! It's $name today.\")\r\n}\r\n<\/pre>\n<p><strong>Input:<\/strong> Wednesday<\/p>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Hello Mugdha! It&#8217;s Wednesday today.<\/div>\n<p>In this example, the &#8216;when&#8217; expression is employed to convert an enum value representing a day of the week into its corresponding name. With a warm greeting, we inform Mugdha about the specific day.<\/p>\n<h3>More Use cases for Kotlin When Expression<\/h3>\n<p>The &#8216;when&#8217; expression commences with the keyword &#8216;when&#8217;, followed by the variable or expression to be evaluated. Each condition is specified using the &#8216;-&gt;&#8217; operator, followed by the code block to be executed when the condition is satisfied. The &#8216;else&#8217; branch, although optional, serves as a fallback when none of the conditions match.<\/p>\n<h4>Using when as a statement with else:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun handleInput(input: Any) {\r\n    when (input) {\r\n        is Int -&gt; println(\"The input is an integer.\")\r\n        is String -&gt; println(\"The input is a string.\")\r\n        is Double -&gt; println(\"The input is a double.\")\r\n        else -&gt; println(\"The input type is unknown.\")\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Input:<\/strong> &#8220;Hello&#8221;<\/p>\n<p><strong> Output: <\/strong><\/p>\n<div class=\"code-output\">The input is a string.<\/div>\n<p><strong>Explanation:<\/strong><\/p>\n<p>The &#8216;handleInput&#8217; function takes an input of type `Any` and uses the &#8216;when&#8217; expression to determine its type. In this example, the input is a string (&#8220;Hello&#8221;), so the corresponding message &#8220;The input is a string&#8221; is printed.<\/p>\n<h4>Using when as a statement without else:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun evaluateScore(score: Int) {\r\n    val grade = when (score) {\r\n        in 90..100 -&gt; \"A\"\r\n        in 80 until 90 -&gt; \"B\"\r\n        in 70 until 80 -&gt; \"C\"\r\n        in 60 until 70 -&gt; \"D\"\r\n        else -&gt; \"F\"\r\n    }\r\n    println(\"Your grade is $grade.\")\r\n}\r\n<\/pre>\n<p><strong>Input:<\/strong> 85<\/p>\n<p><strong>Output<\/strong>:<\/p>\n<div class=\"code-output\">Your grade is B.<\/div>\n<p><strong>Explanation:<\/strong><\/p>\n<p>The &#8216;evaluateScore&#8217; function takes a score as an input and uses the &#8216;when&#8217; expression to determine the corresponding grade. In this example, the score is 85, which falls in the range of 80 to 89, so the grade &#8220;B&#8221; is assigned to the &#8216;grade&#8217; variable. The message &#8220;Your grade is B&#8221; is then printed.<\/p>\n<h3>Different ways to use them when block in Kotlin:<\/h3>\n<h4>Combine multiple branches in one using a comma:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun checkNumber(number: Int) {\r\n    when (number) {\r\n        0, 1 -&gt; println(\"Number is either 0 or 1.\")\r\n        2 -&gt; println(\"Number is 2.\")\r\n        else -&gt; println(\"Number is neither 0, 1, nor 2.\")\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Input<\/strong>: 2<\/p>\n<p><strong>Output:\u00a0 <\/strong><\/p>\n<div class=\"code-output\">Number is 2.<\/div>\n<p><strong>Explanation:<\/strong><\/p>\n<p>The &#8216;checkNumber&#8217; function takes a number as input and uses the &#8216;when&#8217; expression to check its value. In this example, the input is 2, so the branch that matches 2 is executed, printing the message &#8220;Number is 2.&#8221;<\/p>\n<h4>Check the input value in the range or not:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun checkRange(number: Int) {\r\n    when (number) {\r\n        in 1..10 -&gt; println(\"Number is between 1 and 10.\")\r\n        !in 1..10 -&gt; println(\"Number is not between 1 and 10.\")\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Input<\/strong>: 7<\/p>\n<p><strong>Output<\/strong>:<\/p>\n<div class=\"code-output\">Number is between 1 and 10.<\/div>\n<p><strong>Explanation:<\/strong><\/p>\n<p>The &#8216;checkRange&#8217; function takes a number as input and uses the &#8216;when&#8217; expression to check if it falls within the range of 1 to 10 (inclusive). In this example, the input value is 7, which satisfies the condition, so the message &#8220;Number is between 1 and 10&#8221; is printed.<\/p>\n<h4>Check if a given variable is of a certain type or not:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun checkType(value: Any) {\r\n    when (value) {\r\n        is Int -&gt; println(\"Value is of type Int.\")\r\n        is String -&gt; println(\"Value is of type String.\")\r\n        else -&gt; println(\"Value is of an unknown type.\")\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Input<\/strong>: &#8220;Hello&#8221;<\/p>\n<p><strong> Output<\/strong>:<\/p>\n<div class=\"code-output\">Value is of type String.<\/div>\n<p><strong>Explanation:<\/strong><\/p>\n<p>The &#8216;checkType&#8217; function takes a value of type `Any` and uses the &#8216;when&#8217; expression to check its type. In this example, the value is a string, so the message &#8220;Value is of type String&#8221; is printed.<\/p>\n<h3>Using when as an expression:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun isPositive(number: Int): Boolean {\r\n    return when {\r\n        number &gt; 0 -&gt; true\r\n        else -&gt; false\r\n    }\r\n}\r\n\r\n<\/pre>\n<p><strong>Input<\/strong>: -5<\/p>\n<p><strong>Output<\/strong>:<\/p>\n<div class=\"code-output\">false<\/div>\n<p><strong>Explanation:<\/strong><\/p>\n<p>The &#8216;isPositive&#8217; function takes a number as input and uses the &#8216;when&#8217; expression without an expression to check if the number is positive. If the number is greater than 0, the expression evaluates to true; otherwise, it evaluates to false. In this example, the input number is -5, which is not greater than 0, so the output is false.<\/p>\n<h3>Using when without an expression:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun checkNumberType(number: Int) {\r\n    when {\r\n        number &lt; 0 -&gt; println(\"Number is negative.\")\r\n        number &gt; 0 -&gt; println(\"Number is positive.\")\r\n        else -&gt; println(\"Number is zero.\")\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Input<\/strong>: 7<\/p>\n<p><strong>Output<\/strong>:<\/p>\n<div class=\"code-output\">Number is positive.<\/div>\n<p><strong>Explanation:<\/strong><\/p>\n<p>The &#8216;checkNumberType&#8217; function takes a number as input and uses the &#8216;when&#8217; expression without an expression to check its value. In this example, when the number is positive, the message &#8220;Number is positive&#8221; is printed.<\/p>\n<h3>Multiple statements of when using braces:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun checkValue(value: Int) {\r\n    when (value) {\r\n        0 -&gt; {\r\n            println(\"Value is 0.\")\r\n            println(\"It's a special case.\")\r\n        }\r\n        1, 2 -&gt; {\r\n            println(\"Value is either 1 or 2.\")\r\n            println(\"It's another special case.\")\r\n        }\r\n        else -&gt; println(\"Value is not 0, 1, or 2.\")\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Input<\/strong>: 0<\/p>\n<p><strong>Output<\/strong>:<\/p>\n<div class=\"code-output\">Value is 0. It&#8217;s a special case.<\/div>\n<p><strong>Explanation:<\/strong><\/p>\n<p>The &#8216;checkValue&#8217; function takes a value as input and uses the &#8216;when&#8217; expression with multiple statements enclosed in curly braces for each branch. In this example, the input value is 0, which matches the first branch. The two print statements inside the curly braces are executed, resulting in the messages &#8220;Value is 0&#8221; and &#8220;It&#8217;s a special case&#8221; being printed.<\/p>\n<h3>Using &#8216;when in the range:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fun checkTemperature(temperature: Int) {\r\n    when (temperature) {\r\n        in 0..10 -&gt; println(\"It's very cold.\")\r\n        in 11..20 -&gt; println(\"It's cold.\")\r\n        in 21..30 -&gt; println(\"It's moderate.\")\r\n        else -&gt; println(\"It's hot.\")\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Input<\/strong>: 25<\/p>\n<p><strong> Output<\/strong>:<\/p>\n<div class=\"code-output\">It&#8217;s moderate.<\/div>\n<p><strong>Explanation:<\/strong><\/p>\n<p>The &#8216;checkTemperature&#8217; function takes a temperature value as input and uses the &#8216;when&#8217; expression to determine the corresponding temperature range. In this example, the input temperature is 25, which falls in the range of 21 to 30, so the message &#8220;It&#8217;s moderate&#8221; is printed.<\/p>\n<h3>Conclusion<\/h3>\n<p>Kotlin&#8217;s &#8216;when&#8217; expression offers developers a versatile and concise approach to handling diverse conditions. Simplifying the code and enhancing readability enables efficient handling of various scenarios. This article has shed light on the power of Kotlin&#8217;s &#8216;when&#8217; expression, empowering you to make informed decisions in your programming journey.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kotlin, a contemporary programming language, empowers developers with a plethora of efficient features. Among these features, the &#8216;when&#8217; expression stands out as a robust decision-making tool. In this article, we will explore Kotlin&#8217;s &#8216;when&#8217;&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":116531,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27775],"tags":[27973],"class_list":["post-116529","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kotlin-tutorials","tag-kotlin-when-expression"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Kotlin When Expression with Examples - DataFlair<\/title>\n<meta name=\"description\" content=\"Kotlin when expression offers developers a versatile and concise approach to handling diverse conditions. Learn more with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Kotlin When Expression with Examples - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Kotlin when expression offers developers a versatile and concise approach to handling diverse conditions. Learn more with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-07T13:30:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-07T13:33:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/07\/kotlin-when-expression.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Kotlin When Expression with Examples - DataFlair","description":"Kotlin when expression offers developers a versatile and concise approach to handling diverse conditions. Learn more with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/","og_locale":"en_US","og_type":"article","og_title":"Kotlin When Expression with Examples - DataFlair","og_description":"Kotlin when expression offers developers a versatile and concise approach to handling diverse conditions. Learn more with examples.","og_url":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-09-07T13:30:30+00:00","article_modified_time":"2023-09-07T13:33:27+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/07\/kotlin-when-expression.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Kotlin When Expression with Examples","datePublished":"2023-09-07T13:30:30+00:00","dateModified":"2023-09-07T13:33:27+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/"},"wordCount":938,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/07\/kotlin-when-expression.webp","keywords":["Kotlin When Expression"],"articleSection":["Kotlin Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/","url":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/","name":"Kotlin When Expression with Examples - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/07\/kotlin-when-expression.webp","datePublished":"2023-09-07T13:30:30+00:00","dateModified":"2023-09-07T13:33:27+00:00","description":"Kotlin when expression offers developers a versatile and concise approach to handling diverse conditions. Learn more with examples.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/07\/kotlin-when-expression.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/07\/kotlin-when-expression.webp","width":1200,"height":628,"caption":"kotlin when expression"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/kotlin-when-expression\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Kotlin Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/kotlin-tutorials\/"},{"@type":"ListItem","position":3,"name":"Kotlin When Expression with Examples"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/116529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=116529"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/116529\/revisions"}],"predecessor-version":[{"id":120400,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/116529\/revisions\/120400"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/116531"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=116529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=116529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=116529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}