Let's say you have a Hosted Feature Layer named worldEQ which contains data on Earthquakes that have occurred throughout the world for the last 50 years:

You wish to create a view named worldEQView from this Hosted Feature Layer. To do that, you could use the following snippet:
<SPAN class="keyword token">from</SPAN> arcgis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>features <SPAN class="keyword token">import</SPAN> FeatureLayerCollection
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://www.arcgis.com"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"username"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"password"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Search for Source Hosted Feature Layer </SPAN>
source_search <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"world_earthquakes"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
source_flc <SPAN class="operator token">=</SPAN> FeatureLayerCollection<SPAN class="punctuation token">.</SPAN>fromitem<SPAN class="punctuation token">(</SPAN>source_search<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create View from Source Hosted Feature Layer </SPAN>
new_view <SPAN class="operator token">=</SPAN> source_flc<SPAN class="punctuation token">.</SPAN>manager<SPAN class="punctuation token">.</SPAN>create_view<SPAN class="punctuation token">(</SPAN>name<SPAN class="operator token">=</SPAN><SPAN class="string token">"worldEQView"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
This works out great and your view is created:

Let's suppose you next want to use the view to show only earthquakes that occurred before the year 1988. Reviewing the Data tab of the view's Item Details, you see that you can filter by a column year_:

When you set a View Definition, that definition is defined at the service level. If you quickly set a test definition in the ArcGIS Online/Portal for ArcGIS user interface and take a look at the view service's Service Definition, you'll see the property that needs to be updated is viewDefinitionQuery:
Click on 'View' in the View's Item Details page

Next, click on the Layer:

Click on 'JSON'

Scroll all the way to the bottom to see the 'viewDefinitionQuery' property:

Note: changing the value of viewDefinitionQuery also updates the related definitionQuery property
To update the viewDefinitionQuery property with the ArcGIS API for Python, you do the following:
<SPAN class="comment token"># Search for newly created View</SPAN>
view_search <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"worldEQView"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
view_flc <SPAN class="operator token">=</SPAN> FeatureLayerCollection<SPAN class="punctuation token">.</SPAN>fromitem<SPAN class="punctuation token">(</SPAN>view_search<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># The viewDefinitionQuery property appears under layers</SPAN>
view_layer <SPAN class="operator token">=</SPAN> view_flc<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Define a SQL query to filter out events past 1988</SPAN>
view_def <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"viewDefinitionQuery"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"year_ < 1988"</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token"># Update the definition to include the view definition query</SPAN>
view_layer<SPAN class="punctuation token">.</SPAN>manager<SPAN class="punctuation token">.</SPAN>update_definition<SPAN class="punctuation token">(</SPAN>view_def<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>You should be able to see this update reflected after refreshing the view Item Details page > Visualization


Altogether, the script to create a View from the Hosted Feature Layer and then to set a View Definition is:
<SPAN class="keyword token">from</SPAN> arcgis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>features <SPAN class="keyword token">import</SPAN> FeatureLayerCollection
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://www.arcgis.com"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"username"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"password"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Search for Source Hosted Feature Layer</SPAN>
source_search <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"world_earthquakes"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
source_flc <SPAN class="operator token">=</SPAN> FeatureLayerCollection<SPAN class="punctuation token">.</SPAN>fromitem<SPAN class="punctuation token">(</SPAN>source_search<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create View from Source Hosted Feature Layer</SPAN>
new_view <SPAN class="operator token">=</SPAN> source_flc<SPAN class="punctuation token">.</SPAN>manager<SPAN class="punctuation token">.</SPAN>create_view<SPAN class="punctuation token">(</SPAN>name<SPAN class="operator token">=</SPAN><SPAN class="string token">"worldEQView"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Search for newly created View</SPAN>
view_search <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"worldEQView"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
view_flc <SPAN class="operator token">=</SPAN> FeatureLayerCollection<SPAN class="punctuation token">.</SPAN>fromitem<SPAN class="punctuation token">(</SPAN>view_search<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># The viewDefinitionQuery property appears under layers</SPAN>
view_layer <SPAN class="operator token">=</SPAN> view_flc<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Define a SQL query to filter out events past 1988</SPAN>
view_def <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"viewDefinitionQuery"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"year_ < 1988"</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token"># Update the definition to include the view definition query</SPAN>
view_layer<SPAN class="punctuation token">.</SPAN>manager<SPAN class="punctuation token">.</SPAN>update_definition<SPAN class="punctuation token">(</SPAN>view_def<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>This can be generalized into a standalone script like this one:
<SPAN class="keyword token">import</SPAN> sys
<SPAN class="keyword token">from</SPAN> arcgis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>features <SPAN class="keyword token">import</SPAN> FeatureLayerCollection
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">search_layer</SPAN><SPAN class="punctuation token">(</SPAN>conn<SPAN class="punctuation token">,</SPAN>layer_name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
search_results <SPAN class="operator token">=</SPAN> conn<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN>layer_name<SPAN class="punctuation token">,</SPAN> item_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"Feature Layer"</SPAN><SPAN class="punctuation token">)</SPAN>
proper_index <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>i <SPAN class="keyword token">for</SPAN> i<SPAN class="punctuation token">,</SPAN> s <SPAN class="keyword token">in</SPAN> enumerate<SPAN class="punctuation token">(</SPAN>search_results<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="string token">'"'</SPAN> <SPAN class="operator token">+</SPAN> layer_name <SPAN class="operator token">+</SPAN> <SPAN class="string token">'"'</SPAN> <SPAN class="keyword token">in</SPAN> str<SPAN class="punctuation token">(</SPAN>s<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
found_item <SPAN class="operator token">=</SPAN> search_results<SPAN class="punctuation token">[</SPAN>proper_index<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN>
flc <SPAN class="operator token">=</SPAN> FeatureLayerCollection<SPAN class="punctuation token">.</SPAN>fromitem<SPAN class="punctuation token">(</SPAN>found_item<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> flc
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">create_view</SPAN><SPAN class="punctuation token">(</SPAN>conn<SPAN class="punctuation token">,</SPAN> source_flc<SPAN class="punctuation token">,</SPAN> view_name<SPAN class="punctuation token">,</SPAN> layer_index<SPAN class="punctuation token">,</SPAN> view_def<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
new_view <SPAN class="operator token">=</SPAN> source_flc<SPAN class="punctuation token">.</SPAN>manager<SPAN class="punctuation token">.</SPAN>create_view<SPAN class="punctuation token">(</SPAN>name<SPAN class="operator token">=</SPAN>view_name<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Search for newly created View</SPAN>
view_flc <SPAN class="operator token">=</SPAN> search_layer<SPAN class="punctuation token">(</SPAN>conn<SPAN class="punctuation token">,</SPAN> view_name<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># The viewDefinitionQuery property appears under layers</SPAN>
view_layer <SPAN class="operator token">=</SPAN> view_flc<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">[</SPAN>layer_index<SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Update the definition to include the view definition query</SPAN>
view_layer<SPAN class="punctuation token">.</SPAN>manager<SPAN class="punctuation token">.</SPAN>update_definition<SPAN class="punctuation token">(</SPAN>view_def<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"View created"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">main</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
conn <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://www.arcgis.com"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"username"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"password"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Index of the Layer to be filtered</SPAN>
layer_index <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="comment token"># Define a SQL query to filter out events past 1988</SPAN>
view_def <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"viewDefinitionQuery"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"year_ < 1988"</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token"># Search for target Hosted Feature Layer</SPAN>
source_flc <SPAN class="operator token">=</SPAN> search_layer<SPAN class="punctuation token">(</SPAN>conn<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"world_earthquakes"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create View from Hosted Feature Layer</SPAN>
create_view<SPAN class="punctuation token">(</SPAN>conn<SPAN class="punctuation token">,</SPAN> source_flc<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"worldEQView"</SPAN><SPAN class="punctuation token">,</SPAN> layer_index<SPAN class="punctuation token">,</SPAN> view_def<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">'__main__'</SPAN><SPAN class="punctuation token">:</SPAN>
sys<SPAN class="punctuation token">.</SPAN>exit<SPAN class="punctuation token">(</SPAN>main<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>If you need to define an area of interest, this would be approached like so:
<SPAN class="" style="border: 0px; font-weight: inherit;">view_layer.</SPAN>manager<SPAN class="" style="border: 0px; font-weight: inherit;">.</SPAN>update_definition<SPAN class="" style="border: 0px; font-weight: inherit;">(</SPAN>update_dict<SPAN class="" style="border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">
</SPAN><CODE><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">view_def =</SPAN> <SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">{</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"viewLayerDefinition"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">{</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"filter"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">{</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"operator"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"esriSpatialRelIntersects"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"value"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">{</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"geometryType"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"esriGeometryEnvelope"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"geometry"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">{</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"xmin"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">4485937.7074932605</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"ymin"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">1543545.165101517</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN>
<SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"xmax"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">9417043.276225261</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"ymax"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">6239836.182941515</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN>
<SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"spatialReference"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">{</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"wkid"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">102100</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"latestWkid"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">3857</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">}</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">}</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">}</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">}</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">}</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">}
</SPAN>